random-forests

A Rust library for Random Forests.

installation

Add to your Cargo.toml:

text randomforests = "0.1.0"

usage

Add the crate and RandomForests to your code:

```rust extern crate randomforests;

use randomforests::RandomForest; ```

Create a Dataset as collection of Items:

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

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

let mut item3 = Item::new(); item3.insert("lang".tostring(), Value { data: "haskell".tostring() }); item3.insert("typing".tostring(), Value { data: "static".tostring() }); 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:

rust 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:

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

And get the predictions:

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