Module rustlearn::trees::decision_tree [] [src]

A two-class decision tree classifer.

This model implements the CART (Classification and Regression Trees) algorithm for both dense and sparse data. The tree is split by randomly sampling max_features candidate features, then choosing the best split amongst those features using reduction in Gini impurity.

Both binary and numeric features are supported; categorical features without a clear ordering should be one-hot encoded for best results.

The model is specified using hyperparameters

Examples

Fitting the model on the iris dataset is straightforward:

use rustlearn::prelude::*;
use rustlearn::trees::decision_tree::Hyperparameters;
use rustlearn::datasets::iris;

let (X, y) = iris::load_data();

let mut model = Hyperparameters::new(4)
                                .min_samples_split(5)
                                .max_depth(40)
                                .one_vs_rest();

model.fit(&X, &y).unwrap();

let prediction = model.predict(&X).unwrap();

Structs

DecisionTree

A two-class decision tree.

Hyperparameters

Hyperparameters for a DecisionTree model.