Skip to main content

anofox_ml_ensemble/
lib.rs

1//! Bagging, random forest, Extra-Trees, gradient boosting, and AdaBoost ensemble methods.
2//!
3//! This crate provides ensemble learning algorithms that combine multiple
4//! decision trees for improved accuracy and robustness:
5//!
6//! - [`BaggingClassifier`] / [`BaggingRegressor`] -- bootstrap aggregating with
7//!   the full feature set (no random feature subsampling).
8//! - [`RandomForestClassifier`] / [`RandomForestRegressor`] -- bagging with
9//!   bootstrap samples and optional random feature subsets.
10//! - [`ExtraTreesClassifier`] / [`ExtraTreesRegressor`] -- extremely randomized
11//!   trees that use random split thresholds and train on the full dataset
12//!   (no bootstrap).
13//! - [`GradientBoostingClassifier`] / [`GradientBoostingRegressor`] -- sequential
14//!   boosting that fits each tree to the residuals of the ensemble.
15//! - [`AdaBoostClassifier`] / [`AdaBoostRegressor`] -- adaptive boosting that
16//!   re-weights samples to focus on hard examples.
17//!
18//! # Examples
19//!
20//! ```
21//! use ndarray::array;
22//! use anofox_ml_core::{Fit, Predict};
23//! use anofox_ml_ensemble::RandomForestClassifier;
24//!
25//! let x = array![
26//!     [1.0, 0.0],
27//!     [2.0, 0.0],
28//!     [3.0, 0.0],
29//!     [10.0, 1.0],
30//!     [11.0, 1.0],
31//!     [12.0, 1.0]
32//! ];
33//! let y = array![0.0, 0.0, 0.0, 1.0, 1.0, 1.0];
34//!
35//! let rf = RandomForestClassifier::new(20)
36//!     .with_max_depth(Some(3))
37//!     .with_seed(42);
38//! let fitted = Fit::fit(&rf, &x, &y).unwrap();
39//!
40//! let preds = fitted.predict(&x).unwrap();
41//! assert!((preds[0] - 0.0_f64).abs() < 1e-10);
42//! assert!((preds[5] - 1.0_f64).abs() < 1e-10);
43//! ```
44
45pub mod adaboost_classifier;
46pub mod adaboost_regressor;
47pub mod bagging_classifier;
48pub mod bagging_regressor;
49pub mod calibrated_classifier;
50pub mod extra_trees_classifier;
51pub mod extra_trees_regressor;
52pub mod gradient_boosting_classifier;
53pub mod gradient_boosting_regressor;
54pub mod hist_gradient_boosting;
55pub mod isolation_forest;
56pub mod lgbm;
57pub mod random_forest_classifier;
58pub mod random_forest_regressor;
59pub mod stacking_classifier;
60pub mod stacking_regressor;
61pub mod voting_classifier;
62pub mod voting_regressor;
63
64pub use adaboost_classifier::{AdaBoostClassifier, FittedAdaBoostClassifier};
65pub use adaboost_regressor::{AdaBoostLoss, AdaBoostRegressor, FittedAdaBoostRegressor};
66pub use bagging_classifier::{BaggingClassifier, FittedBaggingClassifier};
67pub use bagging_regressor::{BaggingRegressor, FittedBaggingRegressor};
68pub use calibrated_classifier::{CalibratedClassifierCV, CalibrationMethod};
69pub use extra_trees_classifier::{ExtraTreesClassifier, FittedExtraTreesClassifier};
70pub use extra_trees_regressor::{ExtraTreesRegressor, FittedExtraTreesRegressor};
71pub use gradient_boosting_classifier::{
72    FittedGradientBoostingClassifier, GradientBoostingClassifier,
73};
74pub use gradient_boosting_regressor::{FittedGradientBoostingRegressor, GradientBoostingRegressor};
75pub use hist_gradient_boosting::{
76    FittedHistGradientBoostingClassifier, FittedHistGradientBoostingRegressor,
77    HistGradientBoostingClassifier, HistGradientBoostingRegressor,
78};
79pub use isolation_forest::{FittedIsolationForest, IsolationForest};
80pub use lgbm::{
81    BoostingType, FittedLgbmClassifier, FittedLgbmRegressor, LgbmClassWeight, LgbmClassifier,
82    LgbmFitOptions, LgbmObjective, LgbmRegressor,
83};
84pub use random_forest_classifier::{FittedRandomForestClassifier, RandomForestClassifier};
85pub use random_forest_regressor::{FittedRandomForestRegressor, RandomForestRegressor};
86pub use stacking_classifier::{FittedStackingClassifier, StackingClassifier};
87pub use stacking_regressor::StackingRegressor;
88pub use voting_classifier::VotingClassifier;
89pub use voting_regressor::VotingRegressor;