7 releases

0.1.6 Sep 18, 2020
0.1.5 Sep 17, 2020

#612 in Science

Download history 13/week @ 2024-03-11 7/week @ 2024-03-18 5/week @ 2024-03-25 30/week @ 2024-04-01 3/week @ 2024-04-08 6/week @ 2024-04-22 5/week @ 2024-04-29 2/week @ 2024-05-06 4/week @ 2024-05-13 10/week @ 2024-05-20 6/week @ 2024-05-27 13/week @ 2024-06-03 8/week @ 2024-06-10 33/week @ 2024-06-24

54 downloads per month
Used in 2 crates

MIT license

44KB
1K SLoC

randomforest

randomforest Documentation Actions Status Coverage Status License: MIT

A random forest implementation in Rust.

Examples

use randomforest::criterion::Mse;
use randomforest::RandomForestRegressorOptions;
use randomforest::table::TableBuilder;

let features = [
    &[0.0, 2.0, 1.0, 0.0][..],
    &[0.0, 2.0, 1.0, 1.0][..],
    &[1.0, 2.0, 1.0, 0.0][..],
    &[2.0, 1.0, 1.0, 0.0][..],
    &[2.0, 0.0, 0.0, 0.0][..],
    &[2.0, 0.0, 0.0, 1.0][..],
    &[1.0, 0.0, 0.0, 1.0][..],
    &[0.0, 1.0, 1.0, 0.0][..],
    &[0.0, 0.0, 0.0, 0.0][..],
    &[2.0, 1.0, 0.0, 0.0][..],
    &[0.0, 1.0, 0.0, 1.0][..],
    &[1.0, 1.0, 1.0, 1.0][..],

];
let target = [
    25.0, 30.0, 46.0, 45.0, 52.0, 23.0, 43.0, 35.0, 38.0, 46.0, 48.0, 52.0
];

let mut table_builder = TableBuilder::new();
for (xs, y) in features.iter().zip(target.iter()) {
   table_builder.add_row(xs, *y)?;
}
let table = table_builder.build()?;

let regressor = RandomForestRegressorOptions::new()
    .seed(0)
    .fit(Mse, table);
assert_eq!(regressor.predict(&[1.0, 2.0, 0.0, 0.0]), 41.9785);

Dependencies

~2.2–3MB
~60K SLoC