mojolearn.MultiOutputClassifier#

class mojolearn.MultiOutputClassifier(estimator, *, n_jobs=None)[source]#

Bases: _TreesWrapperBase

Fit one classifier per label column.

Follows scikit-learn’s MultiOutputClassifier: fit clones estimator once per column of Y, encodes that column’s labels and fits the clone on them; predict stacks the decoded predictions and predict_proba returns a list with one probability array per output. The columns fit one after another.

Parameters:
  • estimator (estimator) – A mojolearn classifier; it is cloned, never fitted in place.

  • n_jobs (None) – Only None is accepted; any other value raises NotImplementedError.

Variables:
  • estimators_ (list) – One fitted clone per column of Y (fitted on integer class codes).

  • classes_ (list of arrays) – The sorted class labels of each output column.

  • n_features_in_ (int) – Number of features seen in fit.

Examples

>>> import numpy as np, mojolearn
>>> rng = np.random.default_rng(0)
>>> X = rng.random((1000, 8), dtype=np.float32)
>>> Y = np.stack([X[:, 0] > 0.5, X[:, 1] > 0.5], axis=1).astype(np.int64)
>>> model = mojolearn.MultiOutputClassifier(mojolearn.DecisionTreeClassifier()).fit(X, Y)
>>> model.predict(X[:5]).shape
(5, 2)
__init__(estimator, *, n_jobs=None)[source]#

Methods

fit(X, Y[, sample_weight])

Fit one clone of estimator per label column of Y.

get_params([deep])

numeric_mode_used()

The numeric mode this estimator runs in.

predict(X)

Predict every output's labels.

predict_proba(X)

Every output's class probabilities.

set_params(**params)

Set constructor parameters.

vendor_used()

The GPU backend this estimator runs on.

fit(X, Y, sample_weight=None)[source]#

Fit one clone of estimator per label column of Y.

Parameters:
  • X (array of shape (n_samples, n_features)) – Training data, converted to float32.

  • Y (array of shape (n_samples, n_outputs)) – Class labels, one column per output. A row count that differs from X raises ValueError.

  • sample_weight (array of shape (n_samples,), default None) – Passed to every clone’s fit when given.

Returns:

self

predict(X)[source]#

Predict every output’s labels.

Returns:

array of shape (n_samples, n_outputs) – For numeric labels, int64 when every output’s labels are integers, else float64.

predict_proba(X)[source]#

Every output’s class probabilities.

Returns:

list of arrays – One float64 array of shape (n_samples, n_classes_j) per output, its columns in the order of classes_[j].