DocumentationClassesOneVsRestClassifier

Class: 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

Constructors

new OneVsRestClassifier()

new OneVsRestClassifier(opts?): OneVsRestClassifier

Parameters

ParameterTypeDescription
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 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 for more details.

Returns OneVsRestClassifier

Defined in generated/multiclass/OneVsRestClassifier.ts:27

Properties

PropertyTypeDefault valueDefined in
_isDisposedbooleanfalsegenerated/multiclass/OneVsRestClassifier.ts:25
_isInitializedbooleanfalsegenerated/multiclass/OneVsRestClassifier.ts:24
_pyPythonBridgeundefinedgenerated/multiclass/OneVsRestClassifier.ts:23
idstringundefinedgenerated/multiclass/OneVsRestClassifier.ts:20
optsanyundefinedgenerated/multiclass/OneVsRestClassifier.ts:21

Accessors

classes_

Get Signature

get classes_(): Promise<any>

Class labels.

Returns Promise<any>

Defined in generated/multiclass/OneVsRestClassifier.ts:526


estimators_

Get Signature

get estimators_(): Promise<any>

Estimators used for predictions.

Returns Promise<any>

Defined in generated/multiclass/OneVsRestClassifier.ts:499


feature_names_in_

Get Signature

get feature_names_in_(): Promise<ArrayLike>

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

Returns Promise<ArrayLike>

Defined in generated/multiclass/OneVsRestClassifier.ts:607


label_binarizer_

Get Signature

get label_binarizer_(): Promise<any>

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

Returns Promise<any>

Defined in generated/multiclass/OneVsRestClassifier.ts:553


n_features_in_

Get Signature

get n_features_in_(): Promise<number>

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

Returns Promise<number>

Defined in generated/multiclass/OneVsRestClassifier.ts:580


py

Get Signature

get py(): PythonBridge

Returns PythonBridge

Set Signature

set py(pythonBridge): void

Parameters

ParameterType
pythonBridgePythonBridge

Returns void

Defined in generated/multiclass/OneVsRestClassifier.ts:51

Methods

decision_function()

decision_function(opts): Promise<ArrayLike[]>

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.

Parameters

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

Returns Promise<ArrayLike[]>

Defined in generated/multiclass/OneVsRestClassifier.ts:126


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/multiclass/OneVsRestClassifier.ts:107


fit()

fit(opts): Promise<any>

Fit underlying estimators.

Parameters

ParameterTypeDescription
optsobject-
opts.fit_params?anyParameters passed to the estimator.fit method of each sub-estimator.
opts.X?ArrayLikeData.
opts.y?anyMulti-class targets. An indicator matrix turns on multilabel classification.

Returns Promise<any>

Defined in generated/multiclass/OneVsRestClassifier.ts:162


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 MetadataRouter encapsulating routing information.

Returns Promise<any>

Defined in generated/multiclass/OneVsRestClassifier.ts:208


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/multiclass/OneVsRestClassifier.ts:64


partial_fit()

partial_fit(opts): Promise<any>

Partially fit underlying estimators.

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

Parameters

ParameterTypeDescription
optsobject-
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.partial_fit_params?anyParameters passed to the estimator.partial_fit method of each sub-estimator.
opts.X?ArrayLikeData.
opts.y?anyMulti-class targets. An indicator matrix turns on multilabel classification.

Returns Promise<any>

Defined in generated/multiclass/OneVsRestClassifier.ts:246


predict()

predict(opts): Promise<any>

Predict multi-class targets using underlying estimators.

Parameters

ParameterTypeDescription
optsobject-
opts.X?ArrayLikeData.

Returns Promise<any>

Defined in generated/multiclass/OneVsRestClassifier.ts:297


predict_proba()

predict_proba(opts): Promise<ArrayLike[]>

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.

Parameters

ParameterTypeDescription
optsobject-
opts.X?ArrayLikeInput data.

Returns Promise<ArrayLike[]>

Defined in generated/multiclass/OneVsRestClassifier.ts:337


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/multiclass/OneVsRestClassifier.ts:375


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.

Returns Promise<any>

Defined in generated/multiclass/OneVsRestClassifier.ts:423


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/multiclass/OneVsRestClassifier.ts:463