A Rust library for building and using decision trees for classification. This library supports both Gini and Entropy criteria for building decision trees.
- Build decision trees for classification
- Support for Gini impurity and entropy-based information gain
- Flexible configuration for minimum samples split, impurity threshold, and maximum depth
To use this library in your project, add the following line to your Cargo.toml
file:
[dependencies]
decision_tree = { git = "https://github.com/abedinia/rust_decision_tree.git" }
Here is an example of how to use the DecisionTree and ClassificationTree structs to build and use a decision tree for classification.
use decision_tree::classification_tree::ClassificationTree;
fn main() {
let X = vec![
vec![2.0, 3.0],
vec![1.0, 1.0],
vec![4.0, 5.0],
vec![6.0, 7.0],
];
let y = vec![0.0, 1.0, 0.0, 1.0];
let mut tree = ClassificationTree::new("GINI", 2, 1e-7, usize::MAX);
tree.fit(X.clone(), y.clone());
let predictions = tree.predict(X);
println!("{:?}", predictions);
}
The DecisionNode struct represents a node in the decision tree.
The DecisionTree struct provides methods for building and using decision trees.
The ClassificationTree struct builds a decision tree for classification purposes.
To run the tests for this library, use the following command:
cargo test