#[non_exhaustive]pub struct RandomForestClassifier { /* private fields */ }Expand description
Random Forest for classification.
Trains an ensemble of decision trees in parallel, each on a bootstrap sample with a random subset of features. Predictions are by majority vote.
Implementations§
Source§impl RandomForestClassifier
impl RandomForestClassifier
Sourcepub fn n_estimators(self, n: usize) -> Self
pub fn n_estimators(self, n: usize) -> Self
Set number of trees.
Sourcepub fn max_features(self, mf: MaxFeatures) -> Self
pub fn max_features(self, mf: MaxFeatures) -> Self
Set feature selection strategy.
Sourcepub fn min_samples_split(self, n: usize) -> Self
pub fn min_samples_split(self, n: usize) -> Self
Set minimum samples to split.
Sourcepub fn min_samples_leaf(self, n: usize) -> Self
pub fn min_samples_leaf(self, n: usize) -> Self
Set minimum samples per leaf.
Sourcepub fn class_weight(self, cw: ClassWeight) -> Self
pub fn class_weight(self, cw: ClassWeight) -> Self
Set class weighting strategy for imbalanced datasets.
Sourcepub fn fit(&mut self, data: &Dataset) -> Result<()>
pub fn fit(&mut self, data: &Dataset) -> Result<()>
Train the random forest.
OOB votes are accumulated into a shared atomic array during parallel build,
avoiding retention of per-tree vote arrays or bootstrap indices.
Dataset indices are pre-sorted once and shared across all trees to avoid
per-tree sorted_by_feature allocation (~6 MB savings with 16 threads).
Sourcepub fn predict(&self, features: &[Vec<f64>]) -> Result<Vec<f64>>
pub fn predict(&self, features: &[Vec<f64>]) -> Result<Vec<f64>>
Predict class labels by majority vote.
Uses FlatTree::predict_sample for cache-optimal traversal.
Parallelized across samples via rayon.
Sourcepub fn predict_proba(&self, features: &[Vec<f64>]) -> Result<Vec<Vec<f64>>>
pub fn predict_proba(&self, features: &[Vec<f64>]) -> Result<Vec<Vec<f64>>>
Predict class probabilities (average across trees).
Parallelized across samples via rayon.
Sourcepub fn feature_importances(&self) -> Result<Vec<f64>>
pub fn feature_importances(&self) -> Result<Vec<f64>>
Feature importances averaged across all trees.
Sourcepub fn oob_score(&self) -> Option<f64>
pub fn oob_score(&self) -> Option<f64>
Out-of-bag accuracy score (available after fit with bootstrap=true).
Sourcepub fn trees(&self) -> &[DecisionTreeClassifier]
pub fn trees(&self) -> &[DecisionTreeClassifier]
Get individual trees (for visualization or inspection).
Sourcepub fn n_features(&self) -> usize
pub fn n_features(&self) -> usize
Number of features the model was trained on.
Trait Implementations§
Source§impl CalibrableClassifier for RandomForestClassifier
impl CalibrableClassifier for RandomForestClassifier
Source§impl Clone for RandomForestClassifier
impl Clone for RandomForestClassifier
Source§fn clone(&self) -> RandomForestClassifier
fn clone(&self) -> RandomForestClassifier
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Default for RandomForestClassifier
impl Default for RandomForestClassifier
Auto Trait Implementations§
impl Freeze for RandomForestClassifier
impl RefUnwindSafe for RandomForestClassifier
impl Send for RandomForestClassifier
impl Sync for RandomForestClassifier
impl Unpin for RandomForestClassifier
impl UnsafeUnpin for RandomForestClassifier
impl UnwindSafe for RandomForestClassifier
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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