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:
_GBDTAdapterBinary gradient-boosted tree classifier with a scikit-learn interface.
Fits
GradientBoostingwithloss='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 infitandscore, and pickling.saveandloadare 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, son_estimators=Nonemeans 1000 iterations and an automatically chosen learning rate undergrow_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 needeval_setinfit.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 raisesValueError.All parameters are keyword-only.
- Variables:
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
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.
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
Xandy, weighted bysample_weightwhen given.set_params(**params)Set constructor parameters and return
self; unknown names raiseValueError.- 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, andX_evalmust already have the same preprocessing asX(a scikit-learnPipelinedoes 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.