mojolearn.AdaBoostRegressor#

class mojolearn.AdaBoostRegressor(estimator=None, *, n_estimators=50, learning_rate=1.0, loss='linear', random_state=None)[source]#

Bases: _AdaBoostBase

An AdaBoost regressor (AdaBoost.R2).

Follows scikit-learn’s AdaBoostRegressor: each member is fitted on a weighted bootstrap draw of the rows, and predict is the weighted median of the members’ predictions. Any mojolearn regressor can be a member; the default is DecisionTreeRegressor(max_depth=3). The bootstrap draws come from mojolearn’s own random generator, so they differ from scikit-learn’s for the same seed.

Parameters:
  • estimator (estimator or None, default=None) – The member to clone. None uses DecisionTreeRegressor(max_depth=3).

  • n_estimators (int, default=50) – Maximum number of boosting rounds; must be at least 1. Boosting can stop earlier, as in scikit-learn.

  • learning_rate (float, default=1.0) – Shrinks each member’s weight; must be > 0.

  • loss ({“linear”, “square”, “exponential”}, default=”linear”) – Loss used to update the row weights after each round.

  • random_state (int or None, default=None) – Seed for the members’ seeds and the bootstrap draws. None means seed 0, so repeated fits are the same (unlike scikit-learn). A RandomState object raises ValueError.

Variables:
  • estimators_ (list of estimators) – The fitted members.

  • estimator_weights_ (list of float) – Weight of each member.

  • estimator_errors_ (list of float) – Weighted average loss of each member.

  • 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 @ rng.random(8, dtype=np.float32)
>>> model = mojolearn.AdaBoostRegressor(n_estimators=50, random_state=0).fit(X, y)
>>> pred = model.predict(X)
__init__(estimator=None, *, n_estimators=50, learning_rate=1.0, loss='linear', random_state=None)[source]#

Methods

fit(X, y[, sample_weight])

Fit the boosted ensemble.

get_params([deep])

numeric_mode_used()

The numeric mode this estimator runs in.

predict(X)

Weighted median of the members' predictions.

set_params(**params)

Set constructor parameters.

vendor_used()

The GPU backend this estimator runs on.

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

Fit the boosted ensemble.

Parameters:
  • X (array-like of shape (n_samples, n_features)) – Training data, read as float32.

  • y (array-like of shape (n_samples,)) – Target values, read as float32.

  • sample_weight (array-like of shape (n_samples,), default=None) – Initial row weights; must be finite, nonnegative and have a positive total. None weights every row equally.

Returns:

self

predict(X)[source]#

Weighted median of the members’ predictions.