Class: ComplementNB

The Complement Naive Bayes classifier described in Rennie et al. (2003).

The Complement Naive Bayes classifier was designed to correct the “severe assumptions” made by the standard Multinomial Naive Bayes classifier. It is particularly suited for imbalanced data sets.

Read more in the User Guide.

Python Reference

Constructors

new ComplementNB()

new ComplementNB(opts?): ComplementNB

Parameters

ParameterTypeDescription
opts?object-
opts.alpha?number | ArrayLikeAdditive (Laplace/Lidstone) smoothing parameter (set alpha=0 and force_alpha=true, for no smoothing).
opts.class_prior?ArrayLikePrior probabilities of the classes. Not used.
opts.fit_prior?booleanOnly used in edge case with a single class in the training set.
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.
opts.norm?booleanWhether or not a second normalization of the weights is performed. The default behavior mirrors the implementations found in Mahout and Weka, which do not follow the full algorithm described in Table 9 of the paper.

Returns ComplementNB

Defined in generated/naive_bayes/ComplementNB.ts:25

Properties

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


class_log_prior_

Get Signature

get class_log_prior_(): Promise<ArrayLike>

Smoothed empirical log probability for each class. Only used in edge case with a single class in the training set.

Returns Promise<ArrayLike>

Defined in generated/naive_bayes/ComplementNB.ts:585


classes_

Get Signature

get classes_(): Promise<ArrayLike>

Class labels known to the classifier

Returns Promise<ArrayLike>

Defined in generated/naive_bayes/ComplementNB.ts:610


feature_all_

Get Signature

get feature_all_(): Promise<ArrayLike>

Number of samples encountered for each feature during fitting. This value is weighted by the sample weight when provided.

Returns Promise<ArrayLike>

Defined in generated/naive_bayes/ComplementNB.ts:633


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/ComplementNB.ts:658


feature_log_prob_

Get Signature

get feature_log_prob_(): Promise<ArrayLike[]>

Empirical weights for class complements.

Returns Promise<ArrayLike[]>

Defined in generated/naive_bayes/ComplementNB.ts:683


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/ComplementNB.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/ComplementNB.ts:708


py

Get Signature

get py(): PythonBridge

Returns PythonBridge

Set Signature

set py(pythonBridge): void

Parameters

ParameterType
pythonBridgePythonBridge

Returns void

Defined in generated/naive_bayes/ComplementNB.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/ComplementNB.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/ComplementNB.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/ComplementNB.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/ComplementNB.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/ComplementNB.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/ComplementNB.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/ComplementNB.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/ComplementNB.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/ComplementNB.ts:367


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/ComplementNB.ts:401


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/ComplementNB.ts:447


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/ComplementNB.ts:483


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/ComplementNB.ts:526