Skip to main content

Module gradient_boosting

Module gradient_boosting 

Source
Expand description

Gradient boosting classifiers and regressors.

This module provides GradientBoostingClassifier and GradientBoostingRegressor, which build ensembles of decision trees sequentially. Each tree fits the negative gradient (pseudo-residuals) of the loss function, progressively reducing prediction error.

§Regression Losses

  • LeastSquares (L2): mean squared error; pseudo-residuals are y - F(x).
  • Lad (L1): least absolute deviation; pseudo-residuals are sign(y - F(x)).
  • Huber: a blend of L2 (for small residuals) and L1 (for large residuals), controlled by the alpha quantile parameter (default 0.9).

§Classification Loss

  • LogLoss: binary and multiclass logistic loss. For binary classification a single model is trained on log-odds; for K-class problems K trees are built per boosting round (one-vs-rest in probability space via softmax).

§Examples

use ferrolearn_tree::GradientBoostingRegressor;
use ferrolearn_core::{Fit, Predict};
use ndarray::{array, Array1, Array2};

let x = Array2::from_shape_vec((8, 1), vec![
    1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0,
]).unwrap();
let y = array![1.0, 1.0, 1.0, 1.0, 5.0, 5.0, 5.0, 5.0];

let model = GradientBoostingRegressor::<f64>::new()
    .with_n_estimators(50)
    .with_learning_rate(0.1)
    .with_random_state(42);
let fitted = model.fit(&x, &y).unwrap();
let preds = fitted.predict(&x).unwrap();
assert_eq!(preds.len(), 8);

Structs§

FittedGradientBoostingClassifier
A fitted gradient boosting classifier.
FittedGradientBoostingRegressor
A fitted gradient boosting regressor.
GradientBoostingClassifier
Gradient boosting classifier.
GradientBoostingRegressor
Gradient boosting regressor.

Enums§

ClassificationLoss
Loss function for gradient boosting classification.
RegressionLoss
Loss function for gradient boosting regression.