#[non_exhaustive]pub struct HistGradientBoostingClassifier { /* private fields */ }Expand description
Histogram-based Gradient Boosting for classification (binary + multiclass).
Uses the same O(256) histogram approach as the regressor, with log-loss for binary classification and softmax for multiclass. Leaf-wise tree growth with Newton-Raphson leaf correction.
§Example
use scry_learn::dataset::Dataset;
use scry_learn::tree::HistGradientBoostingClassifier;
let features = vec![
vec![1.0, 2.0, 3.0, 4.0, 5.0, 6.0],
vec![0.1, 0.2, 0.3, 0.4, 0.5, 0.6],
];
let target = vec![0.0, 0.0, 0.0, 1.0, 1.0, 1.0];
let data = Dataset::new(features, target, vec!["x1".into(), "x2".into()], "class");
let mut model = HistGradientBoostingClassifier::new()
.n_estimators(50)
.learning_rate(0.1)
.max_leaf_nodes(31);
model.fit(&data).unwrap();
let preds = model.predict(&[vec![1.5, 0.15], vec![5.5, 0.55]]).unwrap();
assert_eq!(preds[0], 0.0);
assert_eq!(preds[1], 1.0);Implementations§
Source§impl HistGradientBoostingClassifier
impl HistGradientBoostingClassifier
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new classifier with default parameters.
§Example
use scry_learn::tree::HistGradientBoostingClassifier;
let model = HistGradientBoostingClassifier::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 leaf nodes per tree (default: 31).
Sourcepub fn min_samples_leaf(self, n: usize) -> Self
pub fn min_samples_leaf(self, n: usize) -> Self
Set minimum samples per leaf (default: 20).
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 classifier.
Sourcepub fn predict(&self, features: &[Vec<f64>]) -> Result<Vec<f64>>
pub fn predict(&self, features: &[Vec<f64>]) -> Result<Vec<f64>>
Predict class labels for new samples.
Sourcepub fn predict_proba(&self, features: &[Vec<f64>]) -> Result<Vec<Vec<f64>>>
pub fn predict_proba(&self, features: &[Vec<f64>]) -> Result<Vec<Vec<f64>>>
Predict class probabilities for new samples.
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_predictions_val(&self) -> &[f64]
pub fn init_predictions_val(&self) -> &[f64]
Initial predictions per class.
Sourcepub fn class_tree_node_views(&self) -> Vec<Vec<Vec<HistNodeView>>>
pub fn class_tree_node_views(&self) -> Vec<Vec<Vec<HistNodeView>>>
Convert internal HistTree nodes to public HistNodeView arrays for ONNX export.
Returns class_tree_views[class_idx][tree_idx] = Vec of HistNodeView.
Trait Implementations§
Source§impl CalibrableClassifier for HistGradientBoostingClassifier
impl CalibrableClassifier for HistGradientBoostingClassifier
Source§impl Clone for HistGradientBoostingClassifier
impl Clone for HistGradientBoostingClassifier
Source§fn clone(&self) -> HistGradientBoostingClassifier
fn clone(&self) -> HistGradientBoostingClassifier
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 HistGradientBoostingClassifier
impl RefUnwindSafe for HistGradientBoostingClassifier
impl Send for HistGradientBoostingClassifier
impl Sync for HistGradientBoostingClassifier
impl Unpin for HistGradientBoostingClassifier
impl UnsafeUnpin for HistGradientBoostingClassifier
impl UnwindSafe for HistGradientBoostingClassifier
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