Crates.io | dendritic-trees |
lib.rs | dendritic-trees |
version | 1.5.0 |
source | src |
created_at | 2024-10-28 13:25:42.581203 |
updated_at | 2024-11-01 19:43:32.763744 |
description | Pacakge for tree based modeling |
homepage | |
repository | |
max_upload_size | |
id | 1425618 |
size | 843,404 |
This crate contains all tree based machine learning models. Contains standard decision tree and random forest classifier and regressors.
The dendritic project is a toy machine learning library built for learning and research purposes. It is not advised by the maintainer to use this library as a production ready machine learning library. This is a project that is still very much a work in progress.
This is an example of using the decision tree classifier model provided by dendritic.
The example below uses decision trees but random forest can be used with RandomForestClassifier
or RandomForestRegressor
.
use dendritic_ndarray::ndarray::NDArray;
use dendritic_ndarray::ops::*;
use dendritic_metrics::loss::*;
use dendritic_metrics::utils::*;
use dendritic_trees::decision_tree::*;
use dendritic_datasets::iris::*;
fn main() {
// load data
let data_path = "../dendritic-datasets/data/iris.parquet";
let max_depth = 3;
let samples_split = 3;
let (x_train_test, y_train_test) = load_iris(data_path).unwrap();
let (x_train, y_train) = load_all_iris(data_path).unwrap();
// Decision tree classifier model
let mut model = DecisionTreeClassifier::new(
max_depth,
samples_split,
gini_impurity
);
model.fit(&x_train, &y_train);
let sample_index = 100;
let x_test = x_train_test.batch(5).unwrap();
let y_test = y_train_test.batch(5).unwrap();
let y_pred = model.predict(x_test[sample_index].clone());
println!("Actual: {:?}", y_test[sample_index]);
println!("Prediction: {:?}", y_pred.values());
}