mojolearn.AdaBoostClassifier#

class mojolearn.AdaBoostClassifier(estimator=None, *, n_estimators=50, learning_rate=1.0, algorithm='SAMME', random_state=None)[source]#

Bases: _AdaBoostBase

An AdaBoost classifier (SAMME).

Follows scikit-learn’s AdaBoostClassifier with the SAMME algorithm: each member is fitted on every row, with the current boosting weights (scaled by the number of rows, float32) as its sample_weight. Any mojolearn classifier that accepts sample_weight can be a member; the default is a decision stump, DecisionTreeClassifier(max_depth=1).

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

  • 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.

  • algorithm ({“SAMME”}, default=”SAMME”) – Only SAMME is supported (scikit-learn 1.6 removed SAMME.R); "SAMME.R" raises NotImplementedError.

  • random_state (int or None, default=None) – Seed for the members’ seeds. 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 training error of each member.

  • classes_ (array of shape (n_classes,)) – Class labels seen in fit.

  • n_classes_ (int) – Number of classes.

  • 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[:, 0] + X[:, 1] > 1.0).astype(np.int32)
>>> model = mojolearn.AdaBoostClassifier(n_estimators=50).fit(X, y)
>>> proba = model.predict_proba(X)
__init__(estimator=None, *, n_estimators=50, learning_rate=1.0, algorithm='SAMME', random_state=None)[source]#

Methods

decision_function(X)

Weighted member votes, float64.

fit(X, y[, sample_weight])

Fit the boosted ensemble.

get_params([deep])

numeric_mode_used()

The numeric mode this estimator runs in.

predict(X)

Predict the class with the highest weighted vote.

predict_proba(X)

Class probabilities from the decision function (softmax), float64.

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. NaN or infinity raises ValueError.

  • y (array-like of shape (n_samples,)) – Class labels; at least two classes are required.

  • 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

Raises:

ValueError – If the first member is worse than random guessing.

decision_function(X)[source]#

Weighted member votes, float64.

Returns shape (n_samples,) for two classes (positive favors classes_[1]) and (n_samples, n_classes) otherwise.

predict_proba(X)[source]#

Class probabilities from the decision function (softmax), float64.

Returns an array of shape (n_samples, n_classes), columns in the order of classes_.

predict(X)[source]#

Predict the class with the highest weighted vote.