mojolearn.OneVsRestClassifier#
- class mojolearn.OneVsRestClassifier(estimator, *, n_jobs=None, verbose=0)#
Multiclass classification with one binary classifier per class.
Follows scikit-learn’s
OneVsRestClassifier:fittrains one clone ofestimatorper class (that class against the rest), or a single clone when there are two classes.predicttakes the class whose clone scores highest, usingdecision_functionwhen the estimator has one, else the positive-class column ofpredict_proba. The classes fit one after another.Differs from scikit-learn: in
predict_proba, a row whose per-class probabilities are all 0 gets uniform probabilities (scikit-learn divides 0 by 0).- Parameters:
estimator (estimator) – A mojolearn binary classifier; it is cloned, never fitted in place.
n_jobs (None) – Only None is accepted; any other value raises
NotImplementedError.verbose (int, default 0) – Only 0 is accepted; any other value raises
NotImplementedError.
- Variables:
Examples
>>> import numpy as np, mojolearn >>> rng = np.random.default_rng(0) >>> X = rng.random((1000, 8), dtype=np.float32) >>> y = (3 * X[:, 0]).astype(np.int32) >>> model = mojolearn.OneVsRestClassifier(mojolearn.LogisticRegression()).fit(X, y) >>> model.predict_proba(X[:5]).shape (5, 3)
Methods
fit(X, y)Fit one binary clone per class.
get_params([deep])The numeric mode this estimator runs in.
predict(X)Predict the class whose binary classifier scores highest.
Class probabilities.
set_params(**params)Set constructor parameters.
The GPU backend this estimator runs on.
- fit(X, y)#
Fit one binary clone per class.
- Parameters:
X (array of shape (n_samples, n_features)) – Training data, converted to float32.
y (array of shape (n_samples,)) – Class labels; fewer than two classes raise
ValueError.
- Returns:
self
- predict(X)#
Predict the class whose binary classifier scores highest.
- Returns:
array of shape (n_samples,) – Labels from
classes_.
- predict_proba(X)#
Class probabilities.
Each class’s positive-class probability from its clone, with every row normalized to sum to 1 when there are more than two classes. For two classes the rows are
(1 - p, p).- Returns:
array of shape (n_samples, n_classes), float64
- numeric_mode_used()#
The numeric mode this estimator runs in.
- Returns:
str –
'identical'or'fast', read from the compiled binary the estimator uses, not from the argument it was given.
- set_params(**params)#
Set constructor parameters. The estimator is rebuilt through its constructor, so every constructor check runs again and any fitted state is dropped, as a new setting invalidates it.
- vendor_used()#
The GPU backend this estimator runs on.
- Returns:
str –
'metal','cuda'or'hip', read from the compiled binary the estimator uses.