Documentation
Classes
OneVsRestClassifier

OneVsRestClassifier

One-vs-the-rest (OvR) multiclass strategy.

Also known as one-vs-all, this strategy consists in fitting one classifier per class. For each classifier, the class is fitted against all the other classes. In addition to its computational efficiency (only n\_classes classifiers are needed), one advantage of this approach is its interpretability. Since each class is represented by one and one classifier only, it is possible to gain knowledge about the class by inspecting its corresponding classifier. This is the most commonly used strategy for multiclass classification and is a fair default choice.

OneVsRestClassifier can also be used for multilabel classification. To use this feature, provide an indicator matrix for the target y when calling .fit. In other words, the target labels should be formatted as a 2D binary (0/1) matrix, where [i, j] == 1 indicates the presence of label j in sample i. This estimator uses the binary relevance method to perform multilabel classification, which involves training one binary classifier independently for each label.

Read more in the User Guide.

Python Reference (opens in a new tab)

Constructors

constructor()

Signature

new OneVsRestClassifier(opts?: object): OneVsRestClassifier;

Parameters

NameTypeDescription
opts?object-
opts.estimator?anyA regressor or a classifier that implements fit. When a classifier is passed, decision_function will be used in priority and it will fallback to predict_proba if it is not available. When a regressor is passed, predict is used.
opts.n_jobs?numberThe number of jobs to use for the computation: the n\_classes one-vs-rest problems are computed in parallel. undefined means 1 unless in a joblib.parallel\_backend (opens in a new tab) context. \-1 means using all processors. See Glossary for more details.
opts.verbose?numberThe verbosity level, if non zero, progress messages are printed. Below 50, the output is sent to stderr. Otherwise, the output is sent to stdout. The frequency of the messages increases with the verbosity level, reporting all iterations at 10. See joblib.Parallel (opens in a new tab) for more details. Default Value 0

Returns

OneVsRestClassifier

Defined in: generated/multiclass/OneVsRestClassifier.ts:27 (opens in a new tab)

Methods

decision_function()

Decision function for the OneVsRestClassifier.

Return the distance of each sample from the decision boundary for each class. This can only be used with estimators which implement the decision\_function method.

Signature

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

Parameters

NameTypeDescription
optsobject-
opts.X?ArrayLike[]Input data.

Returns

Promise<ArrayLike[]>

Defined in: generated/multiclass/OneVsRestClassifier.ts:129 (opens in a new tab)

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/multiclass/OneVsRestClassifier.ts:110 (opens in a new tab)

fit()

Fit underlying estimators.

Signature

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

Parameters

NameTypeDescription
optsobject-
opts.X?ArrayLikeData.
opts.y?anyMulti-class targets. An indicator matrix turns on multilabel classification.

Returns

Promise<any>

Defined in: generated/multiclass/OneVsRestClassifier.ts:167 (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/multiclass/OneVsRestClassifier.ts:211 (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/multiclass/OneVsRestClassifier.ts:64 (opens in a new tab)

partial_fit()

Partially fit underlying estimators.

Should be used when memory is inefficient to train all data. Chunks of data can be passed in several iteration.

Signature

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

Parameters

NameTypeDescription
optsobject-
opts.X?ArrayLikeData.
opts.classes?anyClasses across all calls to partial_fit. Can be obtained via np.unique(y\_all), where y_all is the target vector of the entire dataset. This argument is only required in the first call of partial_fit and can be omitted in the subsequent calls.
opts.y?anyMulti-class targets. An indicator matrix turns on multilabel classification.

Returns

Promise<any>

Defined in: generated/multiclass/OneVsRestClassifier.ts:251 (opens in a new tab)

predict()

Predict multi-class targets using underlying estimators.

Signature

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

Parameters

NameTypeDescription
optsobject-
opts.X?ArrayLikeData.

Returns

Promise<any>

Defined in: generated/multiclass/OneVsRestClassifier.ts:302 (opens in a new tab)

predict_proba()

Probability estimates.

The returned estimates for all classes are ordered by label of classes.

Note that in the multilabel case, each sample can have any number of labels. This returns the marginal probability that the given sample has the label in question. For example, it is entirely consistent that two labels both have a 90% probability of applying to a given sample.

In the single label multiclass case, the rows of the returned matrix sum to 1.

Signature

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

Parameters

NameTypeDescription
optsobject-
opts.X?ArrayLikeInput data.

Returns

Promise<ArrayLike[]>

Defined in: generated/multiclass/OneVsRestClassifier.ts:343 (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/multiclass/OneVsRestClassifier.ts:382 (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.

Returns

Promise<any>

Defined in: generated/multiclass/OneVsRestClassifier.ts:435 (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/multiclass/OneVsRestClassifier.ts:477 (opens in a new tab)

Properties

_isDisposed

boolean = false

Defined in: generated/multiclass/OneVsRestClassifier.ts:25 (opens in a new tab)

_isInitialized

boolean = false

Defined in: generated/multiclass/OneVsRestClassifier.ts:24 (opens in a new tab)

_py

PythonBridge

Defined in: generated/multiclass/OneVsRestClassifier.ts:23 (opens in a new tab)

id

string

Defined in: generated/multiclass/OneVsRestClassifier.ts:20 (opens in a new tab)

opts

any

Defined in: generated/multiclass/OneVsRestClassifier.ts:21 (opens in a new tab)

Accessors

classes_

Class labels.

Signature

classes_(): Promise<any>;

Returns

Promise<any>

Defined in: generated/multiclass/OneVsRestClassifier.ts:542 (opens in a new tab)

estimators_

Estimators used for predictions.

Signature

estimators_(): Promise<any>;

Returns

Promise<any>

Defined in: generated/multiclass/OneVsRestClassifier.ts:515 (opens in a new tab)

feature_names_in_

Names of features seen during fit. Only defined if the underlying estimator exposes such an attribute when fit.

Signature

feature_names_in_(): Promise<ArrayLike>;

Returns

Promise<ArrayLike>

Defined in: generated/multiclass/OneVsRestClassifier.ts:623 (opens in a new tab)

label_binarizer_

Object used to transform multiclass labels to binary labels and vice-versa.

Signature

label_binarizer_(): Promise<any>;

Returns

Promise<any>

Defined in: generated/multiclass/OneVsRestClassifier.ts:569 (opens in a new tab)

n_features_in_

Number of features seen during fit. Only defined if the underlying estimator exposes such an attribute when fit.

Signature

n_features_in_(): Promise<number>;

Returns

Promise<number>

Defined in: generated/multiclass/OneVsRestClassifier.ts:596 (opens in a new tab)

py

Signature

py(): PythonBridge;

Returns

PythonBridge

Defined in: generated/multiclass/OneVsRestClassifier.ts:51 (opens in a new tab)

Signature

py(pythonBridge: PythonBridge): void;

Parameters

NameType
pythonBridgePythonBridge

Returns

void

Defined in: generated/multiclass/OneVsRestClassifier.ts:55 (opens in a new tab)