Class: CategoricalNB
Naive Bayes classifier for categorical features.
The categorical Naive Bayes classifier is suitable for classification with discrete features that are categorically distributed. The categories of each feature are drawn from a categorical distribution.
Read more in the User Guide.
Constructors
new CategoricalNB()
new CategoricalNB(
opts
?):CategoricalNB
Parameters
Parameter | Type | Description |
---|---|---|
opts ? | object | - |
opts.alpha ? | number | Additive (Laplace/Lidstone) smoothing parameter (set alpha=0 and force_alpha=true , for no smoothing). |
opts.class_prior ? | ArrayLike | Prior probabilities of the classes. If specified, the priors are not adjusted according to the data. |
opts.fit_prior ? | boolean | Whether to learn class prior probabilities or not. If false, a uniform prior will be used. |
opts.force_alpha ? | boolean | If false and alpha is less than 1e-10, it will set alpha to 1e-10. If true , alpha will remain unchanged. This may cause numerical errors if alpha is too close to 0. |
opts.min_categories ? | number | ArrayLike | Minimum number of categories per feature. |
Returns CategoricalNB
Defined in generated/naive_bayes/CategoricalNB.ts:25
Properties
Property | Type | Default value | Defined in |
---|---|---|---|
_isDisposed | boolean | false | generated/naive_bayes/CategoricalNB.ts:23 |
_isInitialized | boolean | false | generated/naive_bayes/CategoricalNB.ts:22 |
_py | PythonBridge | undefined | generated/naive_bayes/CategoricalNB.ts:21 |
id | string | undefined | generated/naive_bayes/CategoricalNB.ts:18 |
opts | any | undefined | generated/naive_bayes/CategoricalNB.ts:19 |
Accessors
category_count_
Get Signature
get category_count_():
Promise
<any
[]>
Holds arrays of shape (n_classes, n_categories of respective feature) for each feature. Each array provides the number of samples encountered for each class and category of the specific feature.
Returns Promise
<any
[]>
Defined in generated/naive_bayes/CategoricalNB.ts:558
class_count_
Get Signature
get class_count_():
Promise
<ArrayLike
>
Number of samples encountered for each class during fitting. This value is weighted by the sample weight when provided.
Returns Promise
<ArrayLike
>
Defined in generated/naive_bayes/CategoricalNB.ts:583
class_log_prior_
Get Signature
get class_log_prior_():
Promise
<ArrayLike
>
Smoothed empirical log probability for each class.
Returns Promise
<ArrayLike
>
Defined in generated/naive_bayes/CategoricalNB.ts:608
classes_
Get Signature
get classes_():
Promise
<ArrayLike
>
Class labels known to the classifier
Returns Promise
<ArrayLike
>
Defined in generated/naive_bayes/CategoricalNB.ts:633
feature_log_prob_
Get Signature
get feature_log_prob_():
Promise
<any
[]>
Holds arrays of shape (n_classes, n_categories of respective feature) for each feature. Each array provides the empirical log probability of categories given the respective feature and class, P(x_i|y)
.
Returns Promise
<any
[]>
Defined in generated/naive_bayes/CategoricalNB.ts:658
feature_names_in_
Get Signature
get feature_names_in_():
Promise
<ArrayLike
>
Names of features seen during fit. Defined only when X
has feature names that are all strings.
Returns Promise
<ArrayLike
>
Defined in generated/naive_bayes/CategoricalNB.ts:708
n_categories_
Get Signature
get n_categories_():
Promise
<ArrayLike
>
Number of categories for each feature. This value is inferred from the data or set by the minimum number of categories.
Returns Promise
<ArrayLike
>
Defined in generated/naive_bayes/CategoricalNB.ts:733
n_features_in_
Get Signature
get n_features_in_():
Promise
<number
>
Number of features seen during fit.
Returns Promise
<number
>
Defined in generated/naive_bayes/CategoricalNB.ts:683
py
Get Signature
get py():
PythonBridge
Returns PythonBridge
Set Signature
set py(
pythonBridge
):void
Parameters
Parameter | Type |
---|---|
pythonBridge | PythonBridge |
Returns void
Defined in generated/naive_bayes/CategoricalNB.ts:61
Methods
dispose()
dispose():
Promise
<void
>
Disposes of the underlying Python resources.
Once dispose()
is called, the instance is no longer usable.
Returns Promise
<void
>
Defined in generated/naive_bayes/CategoricalNB.ts:113
fit()
fit(
opts
):Promise
<any
>
Fit Naive Bayes classifier according to X, y.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.sample_weight ? | ArrayLike | Weights applied to individual samples (1. for unweighted). |
opts.X ? | ArrayLike | Training vectors, where n_samples is the number of samples and n_features is the number of features. Here, each feature of X is assumed to be from a different categorical distribution. It is further assumed that all categories of each feature are represented by the numbers 0, …, n - 1, where n refers to the total number of categories for the given feature. This can, for instance, be achieved with the help of OrdinalEncoder. |
opts.y ? | ArrayLike | Target values. |
Returns Promise
<any
>
Defined in generated/naive_bayes/CategoricalNB.ts:130
get_metadata_routing()
get_metadata_routing(
opts
):Promise
<any
>
Get metadata routing of this object.
Please check User Guide on how the routing mechanism works.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.routing ? | any | A MetadataRequest encapsulating routing information. |
Returns Promise
<any
>
Defined in generated/naive_bayes/CategoricalNB.ts:174
init()
init(
py
):Promise
<void
>
Initializes the underlying Python resources.
This instance is not usable until the Promise
returned by init()
resolves.
Parameters
Parameter | Type |
---|---|
py | PythonBridge |
Returns Promise
<void
>
Defined in generated/naive_bayes/CategoricalNB.ts:74
partial_fit()
partial_fit(
opts
):Promise
<any
>
Incremental fit on a batch of samples.
This method is expected to be called several times consecutively on different chunks of a dataset so as to implement out-of-core or online learning.
This is especially useful when the whole dataset is too big to fit in memory at once.
This method has some performance overhead hence it is better to call partial_fit on chunks of data that are as large as possible (as long as fitting in the memory budget) to hide the overhead.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.classes ? | ArrayLike | List of all the classes that can possibly appear in the y vector. Must be provided at the first call to partial_fit, can be omitted in subsequent calls. |
opts.sample_weight ? | ArrayLike | Weights applied to individual samples (1. for unweighted). |
opts.X ? | ArrayLike | Training vectors, where n_samples is the number of samples and n_features is the number of features. Here, each feature of X is assumed to be from a different categorical distribution. It is further assumed that all categories of each feature are represented by the numbers 0, …, n - 1, where n refers to the total number of categories for the given feature. This can, for instance, be achieved with the help of OrdinalEncoder. |
opts.y ? | ArrayLike | Target values. |
Returns Promise
<any
>
Defined in generated/naive_bayes/CategoricalNB.ts:214
predict()
predict(
opts
):Promise
<ArrayLike
>
Perform classification on an array of test vectors X.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.X ? | ArrayLike [] | The input samples. |
Returns Promise
<ArrayLike
>
Defined in generated/naive_bayes/CategoricalNB.ts:263
predict_joint_log_proba()
predict_joint_log_proba(
opts
):Promise
<ArrayLike
[]>
Return joint log probability estimates for the test vector X.
For each row x of X and class y, the joint log probability is given by log P(x, y) \= log P(y) + log P(x|y),
where log P(y)
is the class prior probability and log P(x|y)
is the class-conditional probability.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.X ? | ArrayLike [] | The input samples. |
Returns Promise
<ArrayLike
[]>
Defined in generated/naive_bayes/CategoricalNB.ts:297
predict_log_proba()
predict_log_proba(
opts
):Promise
<ArrayLike
[]>
Return log-probability estimates for the test vector X.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.X ? | ArrayLike [] | The input samples. |
Returns Promise
<ArrayLike
[]>
Defined in generated/naive_bayes/CategoricalNB.ts:331
predict_proba()
predict_proba(
opts
):Promise
<ArrayLike
[]>
Return probability estimates for the test vector X.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.X ? | ArrayLike [] | The input samples. |
Returns Promise
<ArrayLike
[]>
Defined in generated/naive_bayes/CategoricalNB.ts:365
score()
score(
opts
):Promise
<number
>
Return the mean accuracy on the given test data and labels.
In multi-label classification, this is the subset accuracy which is a harsh metric since you require for each sample that each label set be correctly predicted.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.sample_weight ? | ArrayLike | Sample weights. |
opts.X ? | ArrayLike [] | Test samples. |
opts.y ? | ArrayLike | True labels for X . |
Returns Promise
<number
>
Defined in generated/naive_bayes/CategoricalNB.ts:399
set_fit_request()
set_fit_request(
opts
):Promise
<any
>
Request metadata passed to the fit
method.
Note that this method is only relevant if enable_metadata_routing=True
(see sklearn.set_config
). Please see User Guide on how the routing mechanism works.
The options for each parameter are:
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.sample_weight ? | string | boolean | Metadata routing for sample_weight parameter in fit . |
Returns Promise
<any
>
Defined in generated/naive_bayes/CategoricalNB.ts:445
set_partial_fit_request()
set_partial_fit_request(
opts
):Promise
<any
>
Request metadata passed to the partial_fit
method.
Note that this method is only relevant if enable_metadata_routing=True
(see sklearn.set_config
). Please see User Guide on how the routing mechanism works.
The options for each parameter are:
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.classes ? | string | boolean | Metadata routing for classes parameter in partial_fit . |
opts.sample_weight ? | string | boolean | Metadata routing for sample_weight parameter in partial_fit . |
Returns Promise
<any
>
Defined in generated/naive_bayes/CategoricalNB.ts:481
set_score_request()
set_score_request(
opts
):Promise
<any
>
Request metadata passed to the score
method.
Note that this method is only relevant if enable_metadata_routing=True
(see sklearn.set_config
). Please see User Guide on how the routing mechanism works.
The options for each parameter are:
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.sample_weight ? | string | boolean | Metadata routing for sample_weight parameter in score . |
Returns Promise
<any
>
Defined in generated/naive_bayes/CategoricalNB.ts:524