pub struct RandomForestClassifier { /* private fields */ }Expand description
Random Forest classifier - an ensemble of decision trees.
Combines multiple decision trees trained on bootstrap samples with random feature selection to reduce overfitting and improve accuracy.
Implementations§
Source§impl RandomForestClassifier
impl RandomForestClassifier
Sourcepub fn new(n_estimators: usize) -> RandomForestClassifier
pub fn new(n_estimators: usize) -> RandomForestClassifier
Creates a new Random Forest classifier.
Sourcepub fn with_max_depth(self, max_depth: usize) -> RandomForestClassifier
pub fn with_max_depth(self, max_depth: usize) -> RandomForestClassifier
Sets the maximum depth for each tree.
Sourcepub fn with_random_state(self, random_state: u64) -> RandomForestClassifier
pub fn with_random_state(self, random_state: u64) -> RandomForestClassifier
Sets the random state for reproducibility.
Sourcepub fn score(&self, x: &Matrix<f32>, y: &[usize]) -> f32
pub fn score(&self, x: &Matrix<f32>, y: &[usize]) -> f32
Calculates accuracy score on test data.
Sourcepub fn predict_proba(&self, x: &Matrix<f32>) -> Matrix<f32>
pub fn predict_proba(&self, x: &Matrix<f32>) -> Matrix<f32>
Predict class probabilities for input features.
Sourcepub fn oob_prediction(&self) -> Option<Vec<usize>>
pub fn oob_prediction(&self) -> Option<Vec<usize>>
Returns Out-of-Bag (OOB) predictions for training samples.
Sourcepub fn feature_importances(&self) -> Option<Vec<f32>>
pub fn feature_importances(&self) -> Option<Vec<f32>>
Returns feature importances based on Mean Decrease in Impurity (MDI).
For each split node, the contribution is the weighted gini decrease
n_node·gini − n_left·left_gini − n_right·right_gini
(sklearn tree/_tree.pyx::compute_feature_importances), averaged across
trees and normalized to sum 1. See
contracts/tree-feature-importances-mdi-v1.yaml.
Sourcepub fn save_safetensors<P>(&self, path: P) -> Result<(), String>
pub fn save_safetensors<P>(&self, path: P) -> Result<(), String>
Saves the Random Forest model to a SafeTensors file.
§Errors
Returns an error if the model is unfitted or if saving fails.
Sourcepub fn load_safetensors<P>(path: P) -> Result<RandomForestClassifier, String>
pub fn load_safetensors<P>(path: P) -> Result<RandomForestClassifier, String>
Loads a Random Forest model from a SafeTensors file.
§Errors
Returns an error if loading fails or if the file format is invalid.
Trait Implementations§
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 Debug for RandomForestClassifier
impl Debug for RandomForestClassifier
Source§impl<'de> Deserialize<'de> for RandomForestClassifier
impl<'de> Deserialize<'de> for RandomForestClassifier
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<RandomForestClassifier, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<RandomForestClassifier, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl Estimator for RandomForestClassifier
impl Estimator for RandomForestClassifier
Source§impl Serialize for RandomForestClassifier
impl Serialize for RandomForestClassifier
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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