mojolearn.AdaBoostClassifier#
- class mojolearn.AdaBoostClassifier(estimator=None, *, n_estimators=50, learning_rate=1.0, algorithm='SAMME', random_state=None)[source]#
Bases:
_AdaBoostBaseAn AdaBoost classifier (SAMME).
Follows scikit-learn’s
AdaBoostClassifierwith the SAMME algorithm: each member is fitted on every row, with the current boosting weights (scaled by the number of rows, float32) as itssample_weight. Any mojolearn classifier that acceptssample_weightcan 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"raisesNotImplementedError.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
RandomStateobject raisesValueError.
- Variables:
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
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.
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.