pub struct RandomForestClassifier<State = Untrained> { /* private fields */ }Expand description
Random Forest Classifier
Implementations§
Source§impl RandomForestClassifier<Untrained>
impl RandomForestClassifier<Untrained>
Sourcepub fn n_estimators(self, n_estimators: usize) -> Self
pub fn n_estimators(self, n_estimators: usize) -> Self
Set the number of trees in the forest
Sourcepub fn criterion(self, criterion: SplitCriterion) -> Self
pub fn criterion(self, criterion: SplitCriterion) -> Self
Set the split criterion
Sourcepub fn min_samples_split(self, min_samples_split: usize) -> Self
pub fn min_samples_split(self, min_samples_split: usize) -> Self
Set the minimum samples required to split
Sourcepub fn min_samples_leaf(self, min_samples_leaf: usize) -> Self
pub fn min_samples_leaf(self, min_samples_leaf: usize) -> Self
Set the minimum samples required at a leaf
Sourcepub fn max_features(self, max_features: MaxFeatures) -> Self
pub fn max_features(self, max_features: MaxFeatures) -> Self
Set the maximum features strategy
Sourcepub fn class_weight(self, class_weight: ClassWeight) -> Self
pub fn class_weight(self, class_weight: ClassWeight) -> Self
Set class weighting strategy for imbalanced datasets
Sourcepub fn sampling_strategy(self, sampling_strategy: SamplingStrategy) -> Self
pub fn sampling_strategy(self, sampling_strategy: SamplingStrategy) -> Self
Set sampling strategy for building trees
Sourcepub fn random_state(self, seed: u64) -> Self
pub fn random_state(self, seed: u64) -> Self
Set the random state
Sourcepub fn min_impurity_decrease(self, min_impurity_decrease: f64) -> Self
pub fn min_impurity_decrease(self, min_impurity_decrease: f64) -> Self
Set the minimum impurity decrease
Source§impl RandomForestClassifier<Trained>
impl RandomForestClassifier<Trained>
Sourcepub fn n_features(&self) -> usize
pub fn n_features(&self) -> usize
Get the number of features
Sourcepub fn oob_decision_function(&self) -> Option<&Array2<f64>>
pub fn oob_decision_function(&self) -> Option<&Array2<f64>>
Get the out-of-bag decision function if computed
Sourcepub fn compute_proximity_matrix(&self, x: &Array2<Float>) -> Result<Array2<f64>>
pub fn compute_proximity_matrix(&self, x: &Array2<Float>) -> Result<Array2<f64>>
Compute the proximity matrix between samples
The proximity matrix measures how often pairs of samples end up in the same leaf nodes across all trees in the forest. Values range from 0 to 1, where 1 indicates samples always end up in the same leaves.
Sourcepub fn proximity_matrix(&self) -> Option<&Array2<f64>>
pub fn proximity_matrix(&self) -> Option<&Array2<f64>>
Get the computed proximity matrix
Returns None if the proximity matrix hasn’t been computed yet. Call compute_proximity_matrix() first to calculate it.
Sourcepub fn predict_parallel(&self, x: &Array2<Float>) -> Result<Array1<i32>>
pub fn predict_parallel(&self, x: &Array2<Float>) -> Result<Array1<i32>>
Predict class labels using parallel processing
This method performs prediction in parallel, which can significantly speed up predictions on large datasets when the parallel feature is enabled.
Sourcepub fn predict_proba_parallel(&self, x: &Array2<Float>) -> Result<Array2<f64>>
pub fn predict_proba_parallel(&self, x: &Array2<Float>) -> Result<Array2<f64>>
Predict class probabilities using parallel processing
This method performs probability prediction in parallel, which can significantly speed up predictions on large datasets when the parallel feature is enabled.
Note: Since SmartCore’s RandomForestClassifier doesn’t provide predict_proba, this implementation creates probability estimates by running multiple predictions and averaging the results across different bootstrap samples of the trees.
Sourcepub fn feature_importances(&self) -> Result<Array1<f64>>
pub fn feature_importances(&self) -> Result<Array1<f64>>
Get feature importances
Returns the feature importances (the higher, the more important the feature).
Since SmartCore doesn’t expose detailed tree structure, this implementation uses permutation-based feature importance as an approximation.
Sourcepub fn permutation_feature_importance(
&self,
x: &Array2<Float>,
y: &Array1<i32>,
n_repeats: usize,
) -> Result<Array1<f64>>
pub fn permutation_feature_importance( &self, x: &Array2<Float>, y: &Array1<i32>, n_repeats: usize, ) -> Result<Array1<f64>>
Compute permutation-based feature importance
This method computes feature importance by measuring the decrease in model performance when feature values are randomly permuted.
Trait Implementations§
Source§impl Default for RandomForestClassifier<Untrained>
impl Default for RandomForestClassifier<Untrained>
Source§impl Estimator for RandomForestClassifier<Untrained>
impl Estimator for RandomForestClassifier<Untrained>
Source§type Config = RandomForestConfig
type Config = RandomForestConfig
Source§type Error = SklearsError
type Error = SklearsError
Source§fn validate_config(&self) -> Result<(), SklearsError>
fn validate_config(&self) -> Result<(), SklearsError>
Source§fn check_compatibility(
&self,
n_samples: usize,
n_features: usize,
) -> Result<(), SklearsError>
fn check_compatibility( &self, n_samples: usize, n_features: usize, ) -> Result<(), SklearsError>
Source§fn metadata(&self) -> EstimatorMetadata
fn metadata(&self) -> EstimatorMetadata
Source§impl Fit<ArrayBase<OwnedRepr<f64>, Dim<[usize; 2]>>, ArrayBase<OwnedRepr<i32>, Dim<[usize; 1]>>> for RandomForestClassifier<Untrained>
impl Fit<ArrayBase<OwnedRepr<f64>, Dim<[usize; 2]>>, ArrayBase<OwnedRepr<i32>, Dim<[usize; 1]>>> for RandomForestClassifier<Untrained>
Source§type Fitted = RandomForestClassifier<Trained>
type Fitted = RandomForestClassifier<Trained>
Source§fn fit(self, x: &Array2<Float>, y: &Array1<i32>) -> Result<Self::Fitted>
fn fit(self, x: &Array2<Float>, y: &Array1<i32>) -> Result<Self::Fitted>
Source§fn fit_with_validation(
self,
x: &X,
y: &Y,
_x_val: Option<&X>,
_y_val: Option<&Y>,
) -> Result<(Self::Fitted, FitMetrics), SklearsError>where
Self: Sized,
fn fit_with_validation(
self,
x: &X,
y: &Y,
_x_val: Option<&X>,
_y_val: Option<&Y>,
) -> Result<(Self::Fitted, FitMetrics), SklearsError>where
Self: Sized,
Source§impl Predict<ArrayBase<OwnedRepr<f64>, Dim<[usize; 2]>>, ArrayBase<OwnedRepr<i32>, Dim<[usize; 1]>>> for RandomForestClassifier<Trained>
impl Predict<ArrayBase<OwnedRepr<f64>, Dim<[usize; 2]>>, ArrayBase<OwnedRepr<i32>, Dim<[usize; 1]>>> for RandomForestClassifier<Trained>
Source§fn predict(&self, x: &Array2<Float>) -> Result<Array1<i32>>
fn predict(&self, x: &Array2<Float>) -> Result<Array1<i32>>
Source§fn predict_with_uncertainty(
&self,
x: &X,
) -> Result<(Output, UncertaintyMeasure), SklearsError>
fn predict_with_uncertainty( &self, x: &X, ) -> Result<(Output, UncertaintyMeasure), SklearsError>
Auto Trait Implementations§
impl<State> Freeze for RandomForestClassifier<State>
impl<State> RefUnwindSafe for RandomForestClassifier<State>where
State: RefUnwindSafe,
impl<State> Send for RandomForestClassifier<State>where
State: Send,
impl<State> Sync for RandomForestClassifier<State>where
State: Sync,
impl<State> Unpin for RandomForestClassifier<State>where
State: Unpin,
impl<State> UnwindSafe for RandomForestClassifier<State>where
State: UnwindSafe,
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