#[non_exhaustive]pub struct HistGradientBoostingRegressor { /* private fields */ }Expand description
Histogram-based Gradient Boosting for regression.
Uses pre-binned features and O(256) histogram scans for split finding, delivering 5-10× speedup over standard GBT on large datasets. This is the same algorithmic approach as LightGBM/XGBoost/CatBoost, implemented in pure Rust with no external BLAS dependency.
§Example
use scry_learn::dataset::Dataset;
use scry_learn::tree::HistGradientBoostingRegressor;
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 model = HistGradientBoostingRegressor::new()
.n_estimators(100)
.learning_rate(0.1)
.max_leaf_nodes(31);
model.fit(&data).unwrap();
let preds = model.predict(&[vec![3.0]]).unwrap();
assert!((preds[0] - 6.0).abs() < 1.0);Implementations§
Source§impl HistGradientBoostingRegressor
impl HistGradientBoostingRegressor
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new regressor with default parameters.
§Example
use scry_learn::tree::HistGradientBoostingRegressor;
let model = HistGradientBoostingRegressor::new()
.n_estimators(200)
.learning_rate(0.05);Sourcepub fn n_estimators(self, n: usize) -> Self
pub fn n_estimators(self, n: usize) -> Self
Set number of boosting rounds (default: 100).
Sourcepub fn learning_rate(self, lr: f64) -> Self
pub fn learning_rate(self, lr: f64) -> Self
Set learning rate / shrinkage (default: 0.1).
Sourcepub fn max_leaf_nodes(self, n: usize) -> Self
pub fn max_leaf_nodes(self, n: usize) -> Self
Set maximum number of leaf nodes per tree (default: 31).
This controls tree complexity. LightGBM default is 31.
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 (default: 20).
Sourcepub fn max_depth(self, d: usize) -> Self
pub fn max_depth(self, d: usize) -> Self
Set maximum tree depth (default: 8). Acts as a secondary depth limit.
Sourcepub fn l2_regularization(self, l2: f64) -> Self
pub fn l2_regularization(self, l2: f64) -> Self
Set L2 regularization (default: 0.0).
Sourcepub fn fit(&mut self, data: &Dataset) -> Result<()>
pub fn fit(&mut self, data: &Dataset) -> Result<()>
Train the histogram-based gradient boosting regressor.
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 (total gain, normalized).
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.
Sourcepub fn tree_node_views(&self) -> Vec<Vec<HistNodeView>>
pub fn tree_node_views(&self) -> Vec<Vec<HistNodeView>>
Convert internal HistTree nodes to public HistNodeView arrays for ONNX export. Bin thresholds are converted to raw feature thresholds using the binner.
Trait Implementations§
Source§impl Clone for HistGradientBoostingRegressor
impl Clone for HistGradientBoostingRegressor
Source§fn clone(&self) -> HistGradientBoostingRegressor
fn clone(&self) -> HistGradientBoostingRegressor
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for HistGradientBoostingRegressor
impl RefUnwindSafe for HistGradientBoostingRegressor
impl Send for HistGradientBoostingRegressor
impl Sync for HistGradientBoostingRegressor
impl Unpin for HistGradientBoostingRegressor
impl UnsafeUnpin for HistGradientBoostingRegressor
impl UnwindSafe for HistGradientBoostingRegressor
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