Class: MultinomialNB
Naive Bayes classifier for multinomial models.
The multinomial Naive Bayes classifier is suitable for classification with discrete features (e.g., word counts for text classification). The multinomial distribution normally requires integer feature counts. However, in practice, fractional counts such as tf-idf may also work.
Read more in the User Guide.
Constructors
new MultinomialNB()
new MultinomialNB(
opts
?):MultinomialNB
Parameters
Parameter | Type | Description |
---|---|---|
opts ? | object | - |
opts.alpha ? | number | ArrayLike | 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. |
Returns MultinomialNB
Defined in generated/naive_bayes/MultinomialNB.ts:25
Properties
Property | Type | Default value | Defined in |
---|---|---|---|
_isDisposed | boolean | false | generated/naive_bayes/MultinomialNB.ts:23 |
_isInitialized | boolean | false | generated/naive_bayes/MultinomialNB.ts:22 |
_py | PythonBridge | undefined | generated/naive_bayes/MultinomialNB.ts:21 |
id | string | undefined | generated/naive_bayes/MultinomialNB.ts:18 |
opts | any | undefined | generated/naive_bayes/MultinomialNB.ts:19 |
Accessors
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/MultinomialNB.ts:553
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/MultinomialNB.ts:578
classes_
Get Signature
get classes_():
Promise
<ArrayLike
>
Class labels known to the classifier
Returns Promise
<ArrayLike
>
Defined in generated/naive_bayes/MultinomialNB.ts:603
feature_count_
Get Signature
get feature_count_():
Promise
<ArrayLike
[]>
Number of samples encountered for each (class, feature) during fitting. This value is weighted by the sample weight when provided.
Returns Promise
<ArrayLike
[]>
Defined in generated/naive_bayes/MultinomialNB.ts:628
feature_log_prob_
Get Signature
get feature_log_prob_():
Promise
<ArrayLike
[]>
Empirical log probability of features given a class, P(x_i|y)
.
Returns Promise
<ArrayLike
[]>
Defined in generated/naive_bayes/MultinomialNB.ts:653
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/MultinomialNB.ts:703
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/MultinomialNB.ts:678
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/MultinomialNB.ts:56
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/MultinomialNB.ts:108
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. |
opts.y ? | ArrayLike | Target values. |
Returns Promise
<any
>
Defined in generated/naive_bayes/MultinomialNB.ts:125
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/MultinomialNB.ts:169
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/MultinomialNB.ts:69
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. |
opts.y ? | ArrayLike | Target values. |
Returns Promise
<any
>
Defined in generated/naive_bayes/MultinomialNB.ts:209
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/MultinomialNB.ts:258
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/MultinomialNB.ts:292
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/MultinomialNB.ts:326
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/MultinomialNB.ts:360
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/MultinomialNB.ts:394
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/MultinomialNB.ts:440
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/MultinomialNB.ts:476
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/MultinomialNB.ts:519