mojolearn.GradientBoostingClassifier#

class mojolearn.GradientBoostingClassifier(*, n_estimators=None, max_depth=6, learning_rate=None, l2_leaf_reg=None, border_count=128, random_state=0, leaf_estimation_method=None, leaf_estimation_iterations=None, bootstrap_type=None, bagging_temperature=1.0, subsample=None, od_type=None, od_pvalue=None, od_wait=None, use_best_model=None, best_model_min_trees=1, score_function=None, nan_mode='Min', random_strength=None, use_pointwise_searcher=False, boost_from_average=None, border_build_max_samples=200000, class_weights=None, grow_policy='SymmetricTree', max_leaves=None, min_data_in_leaf=1, min_split_gain=None, min_child_hessian=None, feature_fraction=1.0, feature_border_type='GreedyLogSum', boosting_type=None, fold_len_multiplier=2.0, fold_permutation_block=None, numeric_mode=None)[source]#

Bases: _GBDTAdapter

Binary gradient-boosted tree classifier with a scikit-learn interface.

Fits GradientBoosting with loss='Logloss' on numeric features and keeps the original class labels. Exactly two classes are required; the positive class is the larger of the two sorted labels. Supports sample weights in fit and score, and pickling. save and load are not available; use pickle.

Parameters:
  • n_estimators, max_depth, learning_rate, l2_leaf_reg, border_count, random_state – As in GradientBoosting; every default is that class’s default, so n_estimators=None means 1000 iterations and an automatically chosen learning rate under grow_policy='SymmetricTree'.

  • leaf_estimation_method, leaf_estimation_iterations, bootstrap_type, bagging_temperature, subsample – As in GradientBoosting.

  • od_type, od_pvalue, od_wait, use_best_model, best_model_min_trees – Overfitting detector and best-model truncation, as in GradientBoosting; they need eval_set in fit.

  • score_function, nan_mode, random_strength, use_pointwise_searcher – As in GradientBoosting.

  • boost_from_average, border_build_max_samples, class_weights – As in GradientBoosting.

  • grow_policy, max_leaves, min_data_in_leaf, min_split_gain, min_child_hessian – As in GradientBoosting.

  • feature_fraction, feature_border_type, boosting_type, fold_len_multiplier, fold_permutation_block – As in GradientBoosting.

  • numeric_mode ({‘identical’, ‘deterministic’, ‘fast’} or None, default None) – Numeric mode for this estimator ('fast' on Apple GPUs); None uses the process default. Any other value raises ValueError.

  • All parameters are keyword-only.

Variables:
  • classes_ (list) – The two class labels, sorted.

  • n_classes_ (int) – Always 2.

  • n_features_in_ (int)

  • model_ (str) – The fitted model text.

  • learning_rate_ (loss_curve_, test_loss_curve_, best_iteration_, stopped_early_,) – As on GradientBoosting.

  • numeric_mode_ (str) – The numeric mode the fit used.

Examples

>>> import numpy as np, mojolearn
>>> rng = np.random.default_rng(0)
>>> X = rng.random((1000, 8), dtype=np.float32)
>>> y = np.where(X[:, 0] > 0.5, "yes", "no")
>>> clf = mojolearn.GradientBoostingClassifier(n_estimators=100).fit(X, y)
>>> labels = clf.predict(X)
__init__(*, n_estimators=None, max_depth=6, learning_rate=None, l2_leaf_reg=None, border_count=128, random_state=0, leaf_estimation_method=None, leaf_estimation_iterations=None, bootstrap_type=None, bagging_temperature=1.0, subsample=None, od_type=None, od_pvalue=None, od_wait=None, use_best_model=None, best_model_min_trees=1, score_function=None, nan_mode='Min', random_strength=None, use_pointwise_searcher=False, boost_from_average=None, border_build_max_samples=200000, class_weights=None, grow_policy='SymmetricTree', max_leaves=None, min_data_in_leaf=1, min_split_gain=None, min_child_hessian=None, feature_fraction=1.0, feature_border_type='GreedyLogSum', boosting_type=None, fold_len_multiplier=2.0, fold_permutation_block=None, numeric_mode=None)#

Methods

decision_function(X)

Return the raw float32 margin for each row.

fit(X, y[, sample_weight, eval_set])

Fit the classifier.

get_params([deep])

Return the constructor parameters as a dict.

load(path)

Not available for this estimator; raises NotImplementedError.

predict(X)

Return the predicted class labels, using the original label values.

predict_proba(X)

Return float32 probabilities of shape (n_samples, 2).

save(path)

Not available for this estimator; raises NotImplementedError.

score(X, y[, sample_weight])

Return the accuracy on X and y, weighted by sample_weight when given.

set_params(**params)

Set constructor parameters and return self; unknown names raise ValueError.

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

Fit the classifier.

Parameters:
  • X (array-like of shape (n_samples, n_features)) – Numeric features.

  • y (array-like of shape (n_samples,)) – Labels with exactly two distinct values; otherwise ValueError.

  • sample_weight (array-like of shape (n_samples,), optional)

  • eval_set (tuple (X_eval, y_eval) or list of one such tuple, optional) – Held-out data for the overfitting detector and use_best_model. Its labels must be among the training labels, and X_eval must already have the same preprocessing as X (a scikit-learn Pipeline does not transform it for you).

Returns:

self

decision_function(X)[source]#

Return the raw float32 margin for each row.

A positive margin favors the positive (larger) class; a zero margin predicts the negative class.

predict_proba(X)[source]#

Return float32 probabilities of shape (n_samples, 2).

Columns are [negative, positive] in classes_ order.

predict(X)[source]#

Return the predicted class labels, using the original label values.

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

Return the accuracy on X and y, weighted by sample_weight when given.

Follows scikit-learn’s weighted accuracy. y must have the same label type as the training labels; otherwise TypeError.