mojolearn.OneVsRestClassifier#
- class mojolearn.OneVsRestClassifier(estimator, *, n_jobs=None, verbose=0)[source]#
Bases:
_TreesWrapperBaseMulticlass 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])numeric_mode_used()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.
vendor_used()The GPU backend this estimator runs on.
- fit(X, y)[source]#
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