pub struct AdaptiveRandomForest { /* private fields */ }alloc only.Expand description
Adaptive Random Forest for streaming classification.
An ensemble of n_trees streaming learners, each trained on a
Poisson-weighted bootstrap with a random feature subspace. ADWIN drift
detection automatically resets individual trees when their error rate
changes significantly.
§Example
use irithyll::{AdaptiveRandomForest, StreamingLearner};
use irithyll::ensemble::adaptive_forest::ARFConfig;
use irithyll::learners::linear::StreamingLinearModel;
let config = ARFConfig::builder(5).lambda(6.0).build().unwrap();
let mut arf = AdaptiveRandomForest::new(config, || {
Box::new(StreamingLinearModel::new(0.01))
});
arf.train_one(&[1.0, 0.0], 0.0);
let pred = arf.predict(&[1.0, 0.0]);Implementations§
Source§impl AdaptiveRandomForest
impl AdaptiveRandomForest
Sourcepub fn new<F>(config: ARFConfig, factory: F) -> Self
pub fn new<F>(config: ARFConfig, factory: F) -> Self
Create a new ARF with the given config and learner factory.
The factory closure is called n_trees times to create the initial
ensemble, and again whenever a tree is replaced after drift detection.
Sourcepub fn predict(&self, features: &[f64]) -> f64
pub fn predict(&self, features: &[f64]) -> f64
Predict by majority vote across all trees.
Each tree casts a vote for a class (prediction rounded to nearest integer). The class with the most votes wins.
Sourcepub fn predict_votes(&self, features: &[f64]) -> Vec<(f64, u64)>
pub fn predict_votes(&self, features: &[f64]) -> Vec<(f64, u64)>
Vote counts per predicted class.
Sourcepub fn n_samples_seen(&self) -> u64
pub fn n_samples_seen(&self) -> u64
Total samples processed.
Sourcepub fn tree_accuracies(&self) -> Vec<f64>
pub fn tree_accuracies(&self) -> Vec<f64>
Per-tree accuracy (correct / evaluated).
Sourcepub fn n_drifts_detected(&self) -> usize
pub fn n_drifts_detected(&self) -> usize
Total number of drift-triggered tree replacements.
Trait Implementations§
Source§impl StreamingLearner for AdaptiveRandomForest
impl StreamingLearner for AdaptiveRandomForest
Source§fn train_one(&mut self, features: &[f64], target: f64, _weight: f64)
fn train_one(&mut self, features: &[f64], target: f64, _weight: f64)
Source§fn predict(&self, features: &[f64]) -> f64
fn predict(&self, features: &[f64]) -> f64
Source§fn n_samples_seen(&self) -> u64
fn n_samples_seen(&self) -> u64
Source§fn train(&mut self, features: &[f64], target: f64)
fn train(&mut self, features: &[f64], target: f64)
Auto Trait Implementations§
impl Freeze for AdaptiveRandomForest
impl !RefUnwindSafe for AdaptiveRandomForest
impl Send for AdaptiveRandomForest
impl Sync for AdaptiveRandomForest
impl Unpin for AdaptiveRandomForest
impl UnsafeUnpin for AdaptiveRandomForest
impl !UnwindSafe for AdaptiveRandomForest
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more