Skip to main content

anofox_ml_trees/
lib.rs

1//! CART decision tree classifiers and regressors.
2//!
3//! This crate provides [`DecisionTreeClassifier`] and [`DecisionTreeRegressor`],
4//! implementing the Classification and Regression Trees (CART) algorithm. Trees
5//! support configurable split criteria ([`SplitCriterion`]: Gini, Entropy, MSE),
6//! maximum depth, minimum samples per split, and minimum samples per leaf.
7//!
8//! # Examples
9//!
10//! ```
11//! use ndarray::array;
12//! use anofox_ml_core::{Fit, Predict};
13//! use anofox_ml_trees::DecisionTreeClassifier;
14//!
15//! let x = array![[1.0], [2.0], [3.0], [4.0], [5.0], [6.0]];
16//! let y = array![0.0, 0.0, 0.0, 1.0, 1.0, 1.0];
17//!
18//! let tree = DecisionTreeClassifier::new().with_max_depth(Some(3));
19//! let fitted = Fit::fit(&tree, &x, &y).unwrap();
20//!
21//! let preds = fitted.predict(&array![[1.5], [5.5]]).unwrap();
22//! assert!((preds[0] - 0.0_f64).abs() < 1e-10);
23//! assert!((preds[1] - 1.0_f64).abs() < 1e-10);
24//! ```
25
26pub mod classifier;
27pub mod node;
28pub mod regressor;
29pub mod split;
30
31pub use classifier::{DecisionTreeClassifier, FittedDecisionTreeClassifier};
32pub use node::TreeNode;
33pub use regressor::{DecisionTreeRegressor, FittedDecisionTreeRegressor};
34pub use split::{ClassWeight, MaxFeatures, SplitCriterion, SplitStrategy};