Documentation
Classes
ComplementNB

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 (opens in a new tab)

Constructors

constructor()

Signature

new ComplementNB(opts?: object): ComplementNB;

Parameters

NameTypeDescription
opts?object-
opts.alpha?number | ArrayLikeAdditive (Laplace/Lidstone) smoothing parameter (set alpha=0 and force_alpha=true, for no smoothing). Default Value 1
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. Default Value true
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. Default Value false
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. Default Value false

Returns

ComplementNB

Defined in: generated/naive_bayes/ComplementNB.ts:25 (opens in a new tab)

Methods

dispose()

Disposes of the underlying Python resources.

Once dispose() is called, the instance is no longer usable.

Signature

dispose(): Promise<void>;

Returns

Promise<void>

Defined in: generated/naive_bayes/ComplementNB.ts:122 (opens in a new tab)

fit()

Fit Naive Bayes classifier according to X, y.

Signature

fit(opts: object): Promise<any>;

Parameters

NameTypeDescription
optsobject-
opts.X?ArrayLikeTraining vectors, where n\_samples is the number of samples and n\_features is the number of features.
opts.sample_weight?ArrayLikeWeights applied to individual samples (1. for unweighted).
opts.y?ArrayLikeTarget values.

Returns

Promise<any>

Defined in: generated/naive_bayes/ComplementNB.ts:139 (opens in a new tab)

get_metadata_routing()

Get metadata routing of this object.

Please check User Guide on how the routing mechanism works.

Signature

get_metadata_routing(opts: object): Promise<any>;

Parameters

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

Returns

Promise<any>

Defined in: generated/naive_bayes/ComplementNB.ts:188 (opens in a new tab)

init()

Initializes the underlying Python resources.

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

Signature

init(py: PythonBridge): Promise<void>;

Parameters

NameType
pyPythonBridge

Returns

Promise<void>

Defined in: generated/naive_bayes/ComplementNB.ts:76 (opens in a new tab)

partial_fit()

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.

Signature

partial_fit(opts: object): Promise<any>;

Parameters

NameTypeDescription
optsobject-
opts.X?ArrayLikeTraining vectors, where n\_samples is the number of samples and n\_features is the number of features.
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.y?ArrayLikeTarget values.

Returns

Promise<any>

Defined in: generated/naive_bayes/ComplementNB.ts:229 (opens in a new tab)

predict()

Perform classification on an array of test vectors X.

Signature

predict(opts: object): Promise<ArrayLike>;

Parameters

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

Returns

Promise<ArrayLike>

Defined in: generated/naive_bayes/ComplementNB.ts:287 (opens in a new tab)

predict_joint_log_proba()

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.

Signature

predict_joint_log_proba(opts: object): Promise<ArrayLike[]>;

Parameters

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

Returns

Promise<ArrayLike[]>

Defined in: generated/naive_bayes/ComplementNB.ts:322 (opens in a new tab)

predict_log_proba()

Return log-probability estimates for the test vector X.

Signature

predict_log_proba(opts: object): Promise<ArrayLike[]>;

Parameters

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

Returns

Promise<ArrayLike[]>

Defined in: generated/naive_bayes/ComplementNB.ts:358 (opens in a new tab)

predict_proba()

Return probability estimates for the test vector X.

Signature

predict_proba(opts: object): Promise<ArrayLike[]>;

Parameters

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

Returns

Promise<ArrayLike[]>

Defined in: generated/naive_bayes/ComplementNB.ts:393 (opens in a new tab)

score()

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.

Signature

score(opts: object): Promise<number>;

Parameters

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

Returns

Promise<number>

Defined in: generated/naive_bayes/ComplementNB.ts:428 (opens in a new tab)

set_fit_request()

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:

Signature

set_fit_request(opts: object): Promise<any>;

Parameters

NameTypeDescription
optsobject-
opts.sample_weight?string | booleanMetadata routing for sample\_weight parameter in fit.

Returns

Promise<any>

Defined in: generated/naive_bayes/ComplementNB.ts:479 (opens in a new tab)

set_partial_fit_request()

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:

Signature

set_partial_fit_request(opts: object): Promise<any>;

Parameters

NameTypeDescription
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:516 (opens in a new tab)

set_score_request()

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:

Signature

set_score_request(opts: object): Promise<any>;

Parameters

NameTypeDescription
optsobject-
opts.sample_weight?string | booleanMetadata routing for sample\_weight parameter in score.

Returns

Promise<any>

Defined in: generated/naive_bayes/ComplementNB.ts:560 (opens in a new tab)

Properties

_isDisposed

boolean = false

Defined in: generated/naive_bayes/ComplementNB.ts:23 (opens in a new tab)

_isInitialized

boolean = false

Defined in: generated/naive_bayes/ComplementNB.ts:22 (opens in a new tab)

_py

PythonBridge

Defined in: generated/naive_bayes/ComplementNB.ts:21 (opens in a new tab)

id

string

Defined in: generated/naive_bayes/ComplementNB.ts:18 (opens in a new tab)

opts

any

Defined in: generated/naive_bayes/ComplementNB.ts:19 (opens in a new tab)

Accessors

class_count_

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

Signature

class_count_(): Promise<ArrayLike>;

Returns

Promise<ArrayLike>

Defined in: generated/naive_bayes/ComplementNB.ts:595 (opens in a new tab)

class_log_prior_

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

Signature

class_log_prior_(): Promise<ArrayLike>;

Returns

Promise<ArrayLike>

Defined in: generated/naive_bayes/ComplementNB.ts:620 (opens in a new tab)

classes_

Class labels known to the classifier

Signature

classes_(): Promise<ArrayLike>;

Returns

Promise<ArrayLike>

Defined in: generated/naive_bayes/ComplementNB.ts:645 (opens in a new tab)

feature_all_

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

Signature

feature_all_(): Promise<ArrayLike>;

Returns

Promise<ArrayLike>

Defined in: generated/naive_bayes/ComplementNB.ts:668 (opens in a new tab)

feature_count_

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

Signature

feature_count_(): Promise<ArrayLike[]>;

Returns

Promise<ArrayLike[]>

Defined in: generated/naive_bayes/ComplementNB.ts:693 (opens in a new tab)

feature_log_prob_

Empirical weights for class complements.

Signature

feature_log_prob_(): Promise<ArrayLike[]>;

Returns

Promise<ArrayLike[]>

Defined in: generated/naive_bayes/ComplementNB.ts:718 (opens in a new tab)

feature_names_in_

Names of features seen during fit. Defined only when X has feature names that are all strings.

Signature

feature_names_in_(): Promise<ArrayLike>;

Returns

Promise<ArrayLike>

Defined in: generated/naive_bayes/ComplementNB.ts:768 (opens in a new tab)

n_features_in_

Number of features seen during fit.

Signature

n_features_in_(): Promise<number>;

Returns

Promise<number>

Defined in: generated/naive_bayes/ComplementNB.ts:743 (opens in a new tab)

py

Signature

py(): PythonBridge;

Returns

PythonBridge

Defined in: generated/naive_bayes/ComplementNB.ts:63 (opens in a new tab)

Signature

py(pythonBridge: PythonBridge): void;

Parameters

NameType
pythonBridgePythonBridge

Returns

void

Defined in: generated/naive_bayes/ComplementNB.ts:67 (opens in a new tab)