randomforests 0.1.1

A simple random forest classifier.
Documentation
  • Coverage
  • 57.89%
    11 out of 19 items documented0 out of 10 items with examples
  • Size
  • Source code size: 42.89 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 4.81 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 16s Average build duration of successful builds.
  • all releases: 16s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • ruivieira/random-forests
    2 0 1
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • ruivieira

https://crates.io/crates/randomforests https://docs.rs/randomforests/

random-forests

A Rust library for Random Forests.

Support for generic impurity measures:

[x] Entropy [x] Gini

installation

Add to your Cargo.toml:

randomforests = "*"

usage

Add the crate and RandomForests to your code:

extern crate randomforests;

use randomforests::RandomForest;

Create a Dataset as collection of Items:

let mut dataset = Dataset::new();
let mut item1 = Item::new();
item1.insert("lang".to_string(), Value { data: "rust".to_string() });
item1.insert("typing".to_string(), Value { data: "static".to_string() });
dataset.push(item1);

let mut item2 = Item::new();
item2.insert("lang".to_string(), Value { data: "python".to_string() } );
item2.insert("typing".to_string(), Value { data: "dynamic".to_string() } );
dataset.push(item2);

let mut item3 = Item::new();
item3.insert("lang".to_string(), Value { data: "haskell".to_string() });
item3.insert("typing".to_string(), Value { data: "static".to_string() });
dataset.push(item3);

Initialise the classifier and train it classifier by passing the Dataset, a TreeConfig, the number of trees and the data subsample size:

let mut config = TreeConfig::new();
config.decision = "lang".to_string();
let forest = RandomForest::build("lang".to_string(), config, &dataset, 100, 3);

Create a question as an Item:

let mut question = Item::new();
question.insert("typing".to_string(), Value { data: "static".to_string() });

And get the predictions:

let answer = RandomForest::predict(forest, question);
// answer = {Value { data: haskell }: 48, Value { data: rust }: 52}