#[non_exhaustive]pub struct GradientBoostingClassifier { /* private fields */ }Expand description
Gradient Boosting for classification (binary + multiclass).
- Binary: fits a single sequence of trees to log-loss pseudo-residuals.
- Multiclass (K > 2): fits K sequences of trees (one-vs-all softmax).
Uses Newton-Raphson leaf correction (second-order gradient step) for
optimal leaf values, matching sklearn’s GradientBoostingClassifier.
§Example
use scry_learn::dataset::Dataset;
use scry_learn::tree::GradientBoostingClassifier;
// Simple linearly separable data.
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 gbc = GradientBoostingClassifier::new()
.n_estimators(50)
.learning_rate(0.1)
.max_depth(2);
gbc.fit(&data).unwrap();
let preds = gbc.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 GradientBoostingClassifier
impl GradientBoostingClassifier
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).
Sourcepub fn min_samples_split(self, n: usize) -> Self
pub fn min_samples_split(self, n: usize) -> Self
Set minimum samples required to split.
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.
Sourcepub fn class_weight(self, cw: ClassWeight) -> Self
pub fn class_weight(self, cw: ClassWeight) -> Self
Set class weighting strategy for imbalanced datasets.
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 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 averaged across all trees.
Sourcepub fn history(&self) -> Option<&TrainingHistory>
pub fn history(&self) -> Option<&TrainingHistory>
Return training history (populated after fit()).
Sourcepub fn class_trees(&self) -> &[Vec<DecisionTreeRegressor>]
pub fn class_trees(&self) -> &[Vec<DecisionTreeRegressor>]
Get tree sequences per class (for inspection or ONNX export).
class_trees()[class_idx][estimator_idx] is the tree for that class/round.
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.
Trait Implementations§
Source§impl CalibrableClassifier for GradientBoostingClassifier
impl CalibrableClassifier for GradientBoostingClassifier
Source§impl Clone for GradientBoostingClassifier
impl Clone for GradientBoostingClassifier
Source§impl Default for GradientBoostingClassifier
impl Default for GradientBoostingClassifier
Auto Trait Implementations§
impl Freeze for GradientBoostingClassifier
impl !RefUnwindSafe for GradientBoostingClassifier
impl Send for GradientBoostingClassifier
impl Sync for GradientBoostingClassifier
impl Unpin for GradientBoostingClassifier
impl UnsafeUnpin for GradientBoostingClassifier
impl !UnwindSafe for GradientBoostingClassifier
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