Skip to content

HistGradientBoostingClassifier

Module: strata.ensemble • Kind: struct • Traits: Classifier, Copyable, Movable
Source: strata/ensemble/hist_gradient_boosting_classifier.mojo

struct HistGradientBoostingClassifier[compute_dtype: DType = DType.float64](Classifier, Copyable, Movable)
from strata.ensemble import HistGradientBoostingClassifier

Histogram-based Gradient Boosting Classifier.

Builds an ensemble of classification trees using discrete UInt8 binning, histogram subtraction, and exact 1st/2nd order gradients for binary and multiclass cross-entropy loss.


Parameter Description
compute_dtype Computational precision data type. Default DType.float64.

def __init__(
out self,
loss: String = "log_loss",
learning_rate: Float64 = 0.1,
max_iter: Int = 100,
max_leaf_nodes: Int = 31,
max_depth: Int = 6,
min_samples_leaf: Int = 20,
l2_regularization: Float64 = 0.0,
max_bins: Int = 256,
min_gain_to_split: Float64 = 0.0,
early_stopping: Bool = True,
validation_fraction: Float64 = 0.1,
n_iter_no_change: Int = 10,
tol: Float64 = 1e-7,
random_state: Int = 42,
)

Initializes a HistGradientBoostingClassifier with validated hyperparameters.

Argument Type Description
loss String —
learning_rate Float64 —
max_iter Int —
max_leaf_nodes Int —
max_depth Int —
min_samples_leaf Int —
l2_regularization Float64 —
max_bins Int —
min_gain_to_split Float64 —
early_stopping Bool —
validation_fraction Float64 —
n_iter_no_change Int —
tol Float64 —
random_state Int —

Attribute Description
loss Loss function to optimize (‘log_loss’ or ‘auto’). Default ‘log_loss’.
learning_rate Shrinkage multiplier for tree leaf outputs η∈(0,1]\eta \in (0, 1]. Default 0.1.
max_iter Maximum number of boosting iterations. Default 100.
max_leaf_nodes Maximum number of leaves per tree. Default 31.
max_depth Maximum tree depth. Default 6.
min_samples_leaf Minimum samples required per leaf node. Default 20.
l2_regularization L2L_2 leaf weight regularization parameter λ≥0\lambda \ge 0. Default 0.0.
max_bins Maximum discrete histogram bins (2≤max_bins≤2562 \le \text{max\_bins} \le 256). Default 256.
min_gain_to_split Minimum gain required to split an internal node. Default 0.0.
early_stopping Whether to use validation-based early stopping. Default True.
validation_fraction Proportion of training data set aside for early stopping. Default 0.1.
n_iter_no_change Maximum consecutive iterations with non-improving validation loss. Default 10.
tol Minimum relative loss improvement threshold. Default 1e-7.
random_state Seed for PRNG shuffling. Default 42. Fitted Attributes:
classes_ Discovered distinct class labels in sorted order.
init_raw_predictions_ Baseline raw margin offsets per class.
bin_thresholds_ Discovered continuous partition boundaries per feature.
trees_ Nested array of fitted trees (T×1T \times 1 for binary, T×KT \times K for multiclass).
n_iter_ Actual number of boosting iterations completed.
is_fitted Boolean flag indicating if estimator has been fitted.
n_features_in_ Number of feature columns seen during fit.

Method Description
HistGradientBoostingClassifier.fit() Fits the ensemble of classification trees on training data (X,y)(X, y).
HistGradientBoostingClassifier.decision_function() Calculates raw margin predictions for samples in XX.
HistGradientBoostingClassifier.predict_proba() Calculates calibrated class probability distributions for XX.
HistGradientBoostingClassifier.predict() Predicts class labels for samples in feature matrix XX.
HistGradientBoostingClassifier.score() Returns the mean accuracy on the given test data and labels.

def fit[feat_dtype: DType, target_dtype: DType](
mut self,
X: Matrix[feat_dtype],
y: List[Scalar[target_dtype]],
)
def fit[feat_dtype: DType, target_dtype: DType](
mut self,
dataset: Dataset[feat_dtype, target_dtype],
)

Overload Note: This method accepts either standard (X, y) inputs or a unified dataset: Dataset container.

Fits the ensemble of classification trees on training data (X,y)(X, y).

Parameter Type Description
X Matrix[feat_dtype] Training feature matrix of shape (N,D)(N, D).
y List[Scalar[target_dtype]] Discrete target classification labels of length NN.
dataset Dataset[feat_dtype, target_dtype] Dataset container holding feature matrix and targets. (Can be provided alternatively in place of (X, y))

HistGradientBoostingClassifier.decision_function()

Section titled “HistGradientBoostingClassifier.decision_function()”
def decision_function[feat_dtype: DType](
self,
X: Matrix[feat_dtype],
) -> Matrix[feat_dtype]

Calculates raw margin predictions for samples in XX.

Parameter Type Description
X Matrix[feat_dtype] Feature matrix.

Returns: Matrix[feat_dtype]


HistGradientBoostingClassifier.predict_proba()

Section titled “HistGradientBoostingClassifier.predict_proba()”
def predict_proba[feat_dtype: DType](
self,
X: Matrix[feat_dtype],
) -> Matrix[feat_dtype]
def predict_proba[feat_dtype: DType, target_dtype: DType](
self,
dataset: Dataset[feat_dtype, target_dtype],
) -> Matrix[feat_dtype]

Overload Note: This method accepts either standard (X, y) inputs or a unified dataset: Dataset container.

Calculates calibrated class probability distributions for XX.

Parameter Type Description
X Matrix[feat_dtype] Feature matrix.
dataset Dataset[feat_dtype, target_dtype] Dataset container holding feature matrix and targets. (Can be provided alternatively in place of (X, y))

Returns: Matrix[feat_dtype]


def predict[feat_dtype: DType](self, X: Matrix[feat_dtype]) -> List[Int]
def predict[feat_dtype: DType, target_dtype: DType](
self,
dataset: Dataset[feat_dtype, target_dtype],
) -> List[Int]

Overload Note: This method accepts either standard (X, y) inputs or a unified dataset: Dataset container.

Predicts class labels for samples in feature matrix XX.

Parameter Type Description
X Matrix[feat_dtype] Feature matrix.
dataset Dataset[feat_dtype, target_dtype] Dataset container holding feature matrix and targets. (Can be provided alternatively in place of (X, y))

Returns: List[Int]


def score[feat_dtype: DType, target_dtype: DType](
self,
X: Matrix[feat_dtype],
y: List[Scalar[target_dtype]],
) -> Float64

Returns the mean accuracy on the given test data and labels.

Parameter Type Description
X Matrix[feat_dtype] Feature matrix.
y List[Scalar[target_dtype]] Target vector / class labels.

Returns: Float64