Class: BernoulliNB

Naive Bayes classifier for multivariate Bernoulli models.

Like MultinomialNB, this classifier is suitable for discrete data. The difference is that while MultinomialNB works with occurrence counts, BernoulliNB is designed for binary/boolean features.

Read more in the User Guide.

Python Reference

Constructors

new BernoulliNB()

new BernoulliNB(opts?): BernoulliNB

Parameters

ParameterTypeDescription
opts?object-
opts.alpha?number | ArrayLikeAdditive (Laplace/Lidstone) smoothing parameter (set alpha=0 and force_alpha=true, for no smoothing).
opts.binarize?numberThreshold for binarizing (mapping to booleans) of sample features. If undefined, input is presumed to already consist of binary vectors.
opts.class_prior?ArrayLikePrior probabilities of the classes. If specified, the priors are not adjusted according to the data.
opts.fit_prior?booleanWhether to learn class prior probabilities or not. If false, a uniform prior will be used.
opts.force_alpha?booleanIf 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 BernoulliNB

Defined in generated/naive_bayes/BernoulliNB.ts:25

Properties

PropertyTypeDefault valueDefined in
_isDisposedbooleanfalsegenerated/naive_bayes/BernoulliNB.ts:23
_isInitializedbooleanfalsegenerated/naive_bayes/BernoulliNB.ts:22
_pyPythonBridgeundefinedgenerated/naive_bayes/BernoulliNB.ts:21
idstringundefinedgenerated/naive_bayes/BernoulliNB.ts:18
optsanyundefinedgenerated/naive_bayes/BernoulliNB.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/BernoulliNB.ts:556


class_log_prior_

Get Signature

get class_log_prior_(): Promise<ArrayLike>

Log probability of each class (smoothed).

Returns Promise<ArrayLike>

Defined in generated/naive_bayes/BernoulliNB.ts:581


classes_

Get Signature

get classes_(): Promise<ArrayLike>

Class labels known to the classifier

Returns Promise<ArrayLike>

Defined in generated/naive_bayes/BernoulliNB.ts:606


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/BernoulliNB.ts:629


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/BernoulliNB.ts:654


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/BernoulliNB.ts:704


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/BernoulliNB.ts:679


py

Get Signature

get py(): PythonBridge

Returns PythonBridge

Set Signature

set py(pythonBridge): void

Parameters

ParameterType
pythonBridgePythonBridge

Returns void

Defined in generated/naive_bayes/BernoulliNB.ts:63

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/BernoulliNB.ts:115


fit()

fit(opts): Promise<any>

Fit Naive Bayes classifier according to X, y.

Parameters

ParameterTypeDescription
optsobject-
opts.sample_weight?ArrayLikeWeights applied to individual samples (1. for unweighted).
opts.X?ArrayLikeTraining vectors, where n_samples is the number of samples and n_features is the number of features.
opts.y?ArrayLikeTarget values.

Returns Promise<any>

Defined in generated/naive_bayes/BernoulliNB.ts:132


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

ParameterTypeDescription
optsobject-
opts.routing?anyA MetadataRequest encapsulating routing information.

Returns Promise<any>

Defined in generated/naive_bayes/BernoulliNB.ts:176


init()

init(py): Promise<void>

Initializes the underlying Python resources.

This instance is not usable until the Promise returned by init() resolves.

Parameters

ParameterType
pyPythonBridge

Returns Promise<void>

Defined in generated/naive_bayes/BernoulliNB.ts:76


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

ParameterTypeDescription
optsobject-
opts.classes?ArrayLikeList 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?ArrayLikeWeights applied to individual samples (1. for unweighted).
opts.X?ArrayLikeTraining vectors, where n_samples is the number of samples and n_features is the number of features.
opts.y?ArrayLikeTarget values.

Returns Promise<any>

Defined in generated/naive_bayes/BernoulliNB.ts:216


predict()

predict(opts): Promise<ArrayLike>

Perform classification on an array of test vectors X.

Parameters

ParameterTypeDescription
optsobject-
opts.X?ArrayLike[]The input samples.

Returns Promise<ArrayLike>

Defined in generated/naive_bayes/BernoulliNB.ts:265


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

ParameterTypeDescription
optsobject-
opts.X?ArrayLike[]The input samples.

Returns Promise<ArrayLike[]>

Defined in generated/naive_bayes/BernoulliNB.ts:299


predict_log_proba()

predict_log_proba(opts): Promise<ArrayLike[]>

Return log-probability estimates for the test vector X.

Parameters

ParameterTypeDescription
optsobject-
opts.X?ArrayLike[]The input samples.

Returns Promise<ArrayLike[]>

Defined in generated/naive_bayes/BernoulliNB.ts:333


predict_proba()

predict_proba(opts): Promise<ArrayLike[]>

Return probability estimates for the test vector X.

Parameters

ParameterTypeDescription
optsobject-
opts.X?ArrayLike[]The input samples.

Returns Promise<ArrayLike[]>

Defined in generated/naive_bayes/BernoulliNB.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

ParameterTypeDescription
optsobject-
opts.sample_weight?ArrayLikeSample weights.
opts.X?ArrayLike[]Test samples.
opts.y?ArrayLikeTrue labels for X.

Returns Promise<number>

Defined in generated/naive_bayes/BernoulliNB.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

ParameterTypeDescription
optsobject-
opts.sample_weight?string | booleanMetadata routing for sample_weight parameter in fit.

Returns Promise<any>

Defined in generated/naive_bayes/BernoulliNB.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

ParameterTypeDescription
optsobject-
opts.classes?string | booleanMetadata routing for classes parameter in partial_fit.
opts.sample_weight?string | booleanMetadata routing for sample_weight parameter in partial_fit.

Returns Promise<any>

Defined in generated/naive_bayes/BernoulliNB.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

ParameterTypeDescription
optsobject-
opts.sample_weight?string | booleanMetadata routing for sample_weight parameter in score.

Returns Promise<any>

Defined in generated/naive_bayes/BernoulliNB.ts:524