imbalanced-ensemble 0.1.0

Ensemble methods for imbalanced learning in Rust - Balanced Random Forest and more
Documentation
// imbalanced-ensemble/src/balanced_random_forest.rs
use imbalanced_core::traits::*;
use ndarray::{Array1, Array2, ArrayView1, ArrayView2};
use std::sync::Arc;

/// Balanced Random Forest for imbalanced classification
pub struct BalancedRandomForest {
    /// Number of trees in the forest
    _n_estimators: usize,
    /// Maximum depth of trees
    max_depth: Option<usize>,
    /// Resampling strategy for each bootstrap
    _resampler: Arc<dyn ResamplingStrategy<Input = (), Output = (Array2<f64>, Array1<i32>), Config = ()>>,
}

impl BalancedRandomForest {
    /// Create a new balanced random forest
    pub fn new(n_estimators: usize) -> Self {
        Self {
            _n_estimators: n_estimators,
            max_depth: None,
            _resampler: Arc::new(DummyResampler),
        }
    }
    
    /// Set maximum depth of trees
    pub fn with_max_depth(mut self, max_depth: usize) -> Self {
        self.max_depth = Some(max_depth);
        self
    }
}

/// Dummy resampler for compilation
struct DummyResampler;

impl ResamplingStrategy for DummyResampler {
    type Input = ();
    type Output = (Array2<f64>, Array1<i32>);
    type Config = ();
    
    fn resample(
        &self,
        x: ArrayView2<f64>,
        y: ArrayView1<i32>,
        _config: &Self::Config,
    ) -> Result<(Array2<f64>, Array1<i32>), ResamplingError> {
        // Just return original data for now
        Ok((x.to_owned(), y.to_owned()))
    }
}