#[non_exhaustive]pub struct GradientBoostingRegressor { /* private fields */ }Expand description
Gradient Boosting for regression.
Builds an additive ensemble of shallow decision trees, each fitting the negative gradient (pseudo-residuals) of the loss function. Supports stochastic subsampling and multiple loss functions.
§Example
use scry_learn::dataset::Dataset;
use scry_learn::tree::GradientBoostingRegressor;
let features = vec![vec![1.0, 2.0, 3.0, 4.0, 5.0]];
let target = vec![2.0, 4.0, 6.0, 8.0, 10.0];
let data = Dataset::new(features, target, vec!["x".into()], "y");
let mut gbr = GradientBoostingRegressor::new()
.n_estimators(50)
.learning_rate(0.1)
.max_depth(3);
gbr.fit(&data).unwrap();
let preds = gbr.predict(&[vec![3.0]]).unwrap();
assert!((preds[0] - 6.0).abs() < 1.0);Implementations§
Source§impl GradientBoostingRegressor
impl GradientBoostingRegressor
Sourcepub fn n_estimators(self, n: usize) -> Self
pub fn n_estimators(self, n: usize) -> Self
Set number of boosting rounds.
Sourcepub fn learning_rate(self, lr: f64) -> Self
pub fn learning_rate(self, lr: f64) -> Self
Set learning rate (shrinkage). Lower values need more estimators.
Sourcepub fn max_depth(self, d: usize) -> Self
pub fn max_depth(self, d: usize) -> Self
Set maximum depth per tree (default: 3, shallow stumps).
Sourcepub fn min_samples_split(self, n: usize) -> Self
pub fn min_samples_split(self, n: usize) -> Self
Set minimum samples required to split an internal node.
Sourcepub fn min_samples_leaf(self, n: usize) -> Self
pub fn min_samples_leaf(self, n: usize) -> Self
Set minimum samples required in a leaf node.
Sourcepub fn n_iter_no_change(self, n: usize) -> Self
pub fn n_iter_no_change(self, n: usize) -> Self
Enable early stopping. Training stops when validation loss does not
improve for n consecutive rounds.
Sourcepub fn validation_fraction(self, frac: f64) -> Self
pub fn validation_fraction(self, frac: f64) -> Self
Set fraction of training data to use as validation for early stopping (default: 0.1).
Sourcepub fn callback(self, cb: Box<dyn TrainingCallback>) -> Self
pub fn callback(self, cb: Box<dyn TrainingCallback>) -> Self
Add a training callback (invoked after each boosting round).
Sourcepub fn n_estimators_used(&self) -> usize
pub fn n_estimators_used(&self) -> usize
Number of estimators actually used (may be less than n_estimators
if early stopping triggered).
Sourcepub fn loss(self, l: RegressionLoss) -> Self
pub fn loss(self, l: RegressionLoss) -> Self
Set the regression loss function.
§Example
use scry_learn::tree::{GradientBoostingRegressor, RegressionLoss};
let gbr = GradientBoostingRegressor::new()
.loss(RegressionLoss::Huber { alpha: 0.9 });Sourcepub fn predict(&self, features: &[Vec<f64>]) -> Result<Vec<f64>>
pub fn predict(&self, features: &[Vec<f64>]) -> Result<Vec<f64>>
Predict values for new samples.
features is row-major: features[sample_idx][feature_idx].
Sourcepub fn feature_importances(&self) -> Result<Vec<f64>>
pub fn feature_importances(&self) -> Result<Vec<f64>>
Feature importances averaged across all trees.
Sourcepub fn early_stopped(&self) -> bool
pub fn early_stopped(&self) -> bool
Whether early stopping was triggered.
Sourcepub fn history(&self) -> Option<&TrainingHistory>
pub fn history(&self) -> Option<&TrainingHistory>
Return training history (populated after fit()).
Sourcepub fn trees(&self) -> &[DecisionTreeRegressor]
pub fn trees(&self) -> &[DecisionTreeRegressor]
Get individual trees (for inspection or ONNX export).
Sourcepub fn n_features(&self) -> usize
pub fn n_features(&self) -> usize
Number of features the model was trained on.
Sourcepub fn learning_rate_val(&self) -> f64
pub fn learning_rate_val(&self) -> f64
Learning rate value.
Sourcepub fn init_prediction_val(&self) -> f64
pub fn init_prediction_val(&self) -> f64
Initial (base) prediction value.
Trait Implementations§
Source§impl Clone for GradientBoostingRegressor
impl Clone for GradientBoostingRegressor
Source§impl Default for GradientBoostingRegressor
impl Default for GradientBoostingRegressor
Auto Trait Implementations§
impl Freeze for GradientBoostingRegressor
impl !RefUnwindSafe for GradientBoostingRegressor
impl Send for GradientBoostingRegressor
impl Sync for GradientBoostingRegressor
impl Unpin for GradientBoostingRegressor
impl UnsafeUnpin for GradientBoostingRegressor
impl !UnwindSafe for GradientBoostingRegressor
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more