mojolearn.VotingRegressor#

class mojolearn.VotingRegressor(estimators, *, weights=None, n_jobs=None, verbose=False)[source]#

Bases: _TreesWrapperBase

Average the predictions of several regressors.

Follows scikit-learn’s VotingRegressor. fit clones every estimator and fits the clones; the estimators you pass are never fitted in place. predict is the weighted average of the members’ predictions. The members fit one after another.

Parameters:
  • estimators (list of (str, estimator)) – Named mojolearn regressors. Names must be unique; an entry whose estimator is the string "drop" is skipped. An empty list, duplicate names, or every entry "drop" raise ValueError.

  • weights (sequence of float, default None) – One weight per active estimator; None weighs them equally. A length that does not match the active estimators raises ValueError in predict.

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

  • verbose (bool, default False) – Only False is accepted; True raises NotImplementedError.

Variables:
  • estimators_ (list) – The fitted clones, in order.

  • named_estimators_ (dict) – The fitted clones by name.

  • 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 = X @ np.arange(8, dtype=np.float32)
>>> model = mojolearn.VotingRegressor(
...     [("rf", mojolearn.RandomForestRegressor()),
...      ("dt", mojolearn.DecisionTreeRegressor())]).fit(X, y)
>>> model.predict(X[:5]).shape
(5,)
__init__(estimators, *, weights=None, n_jobs=None, verbose=False)[source]#

Methods

fit(X, y[, sample_weight])

Fit a clone of every active estimator on X and y.

get_params([deep])

numeric_mode_used()

The numeric mode this estimator runs in.

predict(X)

Weighted average of the members' predictions.

set_params(**params)

Set constructor parameters.

transform(X)

Every member's prediction side by side.

vendor_used()

The GPU backend this estimator runs on.

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

Fit a clone of every active estimator on X and y.

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

  • y (array of shape (n_samples,)) – Targets.

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

Returns:

self

predict(X)[source]#

Weighted average of the members’ predictions.

Returns:

array of shape (n_samples,), float64

transform(X)[source]#

Every member’s prediction side by side.

Returns:

array of shape (n_samples, n_estimators), float64