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
Name | Type | Description |
---|---|---|
opts? | object | - |
opts.estimator? | any | A 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? | number | The 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? | number | The 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
Defined in: generated/multiclass/OneVsRestClassifier.ts:27 (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:418 (opens in a new tab)
estimators_
Estimators used for predictions.
Signature
estimators_(): Promise<any>;
Returns
Promise
<any
>
Defined in: generated/multiclass/OneVsRestClassifier.ts:391 (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:499 (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:445 (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:472 (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
Name | Type |
---|---|
pythonBridge | PythonBridge |
Returns
void
Defined in: generated/multiclass/OneVsRestClassifier.ts:55 (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
Name | Type | Description |
---|---|---|
opts | object | - |
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
Name | Type | Description |
---|---|---|
opts | object | - |
opts.X? | ArrayLike | Data. |
opts.y? | any | Multi-class targets. An indicator matrix turns on multilabel classification. |
Returns
Promise
<any
>
Defined in: generated/multiclass/OneVsRestClassifier.ts:167 (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
Name | Type |
---|---|
py | PythonBridge |
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
Name | Type | Description |
---|---|---|
opts | object | - |
opts.X? | ArrayLike | Data. |
opts.classes? | any | Classes 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? | any | Multi-class targets. An indicator matrix turns on multilabel classification. |
Returns
Promise
<any
>
Defined in: generated/multiclass/OneVsRestClassifier.ts:211 (opens in a new tab)
predict()
Predict multi-class targets using underlying estimators.
Signature
predict(opts: object): Promise<any>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.X? | ArrayLike | Data. |
Returns
Promise
<any
>
Defined in: generated/multiclass/OneVsRestClassifier.ts:262 (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
Name | Type | Description |
---|---|---|
opts | object | - |
opts.X? | ArrayLike | Input data. |
Returns
Promise
<ArrayLike
[]>
Defined in: generated/multiclass/OneVsRestClassifier.ts:303 (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
Name | Type | Description |
---|---|---|
opts | object | - |
opts.X? | ArrayLike [] | Test samples. |
opts.sample_weight? | ArrayLike | Sample weights. |
opts.y? | ArrayLike | True labels for X . |
Returns
Promise
<number
>
Defined in: generated/multiclass/OneVsRestClassifier.ts:342 (opens in a new tab)