pub struct BaggingClassifier<F> {
pub n_estimators: usize,
pub max_samples: f64,
pub max_features: f64,
pub bootstrap: bool,
pub bootstrap_features: bool,
pub random_state: Option<u64>,
pub max_depth: Option<usize>,
/* private fields */
}Expand description
Bootstrap aggregation (bagging) classifier using decision trees.
Each estimator is trained on a bootstrap sample of the data, optionally with a random subset of features. Final predictions are made by majority vote across all estimators.
§Type Parameters
F: The floating-point type (f32orf64).
Fields§
§n_estimators: usizeNumber of estimators in the ensemble.
max_samples: f64Fraction of samples to draw for each estimator (default 1.0).
max_features: f64Fraction of features to draw for each estimator (default 1.0).
bootstrap: boolWhether to sample with replacement (default true).
bootstrap_features: boolWhether to sample features with replacement (default false).
random_state: Option<u64>Random seed for reproducibility.
max_depth: Option<usize>Maximum depth of each base decision tree. None means unlimited.
Implementations§
Source§impl<F: Float> BaggingClassifier<F>
impl<F: Float> BaggingClassifier<F>
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new BaggingClassifier with default settings.
Defaults: n_estimators = 10, max_samples = 1.0,
max_features = 1.0, bootstrap = true,
bootstrap_features = false, random_state = None,
max_depth = None.
Sourcepub fn with_n_estimators(self, n: usize) -> Self
pub fn with_n_estimators(self, n: usize) -> Self
Set the number of estimators.
Sourcepub fn with_max_samples(self, frac: f64) -> Self
pub fn with_max_samples(self, frac: f64) -> Self
Set the fraction of samples to draw per estimator.
Sourcepub fn with_max_features(self, frac: f64) -> Self
pub fn with_max_features(self, frac: f64) -> Self
Set the fraction of features to draw per estimator.
Sourcepub fn with_bootstrap(self, bootstrap: bool) -> Self
pub fn with_bootstrap(self, bootstrap: bool) -> Self
Set whether to sample with replacement.
Sourcepub fn with_bootstrap_features(self, bootstrap_features: bool) -> Self
pub fn with_bootstrap_features(self, bootstrap_features: bool) -> Self
Set whether to sample features with replacement.
Sourcepub fn with_random_state(self, seed: u64) -> Self
pub fn with_random_state(self, seed: u64) -> Self
Set the random seed for reproducibility.
Sourcepub fn with_max_depth(self, max_depth: Option<usize>) -> Self
pub fn with_max_depth(self, max_depth: Option<usize>) -> Self
Set the maximum depth of each base decision tree.
Trait Implementations§
Source§impl<F: Clone> Clone for BaggingClassifier<F>
impl<F: Clone> Clone for BaggingClassifier<F>
Source§fn clone(&self) -> BaggingClassifier<F>
fn clone(&self) -> BaggingClassifier<F>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<F: Debug> Debug for BaggingClassifier<F>
impl<F: Debug> Debug for BaggingClassifier<F>
Source§impl<F: Float> Default for BaggingClassifier<F>
impl<F: Float> Default for BaggingClassifier<F>
Source§impl<F: Float + Send + Sync + 'static> Fit<ArrayBase<OwnedRepr<F>, Dim<[usize; 2]>>, ArrayBase<OwnedRepr<usize>, Dim<[usize; 1]>>> for BaggingClassifier<F>
impl<F: Float + Send + Sync + 'static> Fit<ArrayBase<OwnedRepr<F>, Dim<[usize; 2]>>, ArrayBase<OwnedRepr<usize>, Dim<[usize; 1]>>> for BaggingClassifier<F>
Source§fn fit(
&self,
x: &Array2<F>,
y: &Array1<usize>,
) -> Result<FittedBaggingClassifier<F>, FerroError>
fn fit( &self, x: &Array2<F>, y: &Array1<usize>, ) -> Result<FittedBaggingClassifier<F>, FerroError>
Fit the bagging classifier by building n_estimators decision trees in parallel.
Each tree is trained on a (bootstrap) sample of the data with a random subset of features.
§Errors
Returns FerroError::ShapeMismatch if x and y have different
numbers of samples.
Returns FerroError::InsufficientSamples if there are no samples.
Returns FerroError::InvalidParameter for invalid hyperparameters.
Source§type Fitted = FittedBaggingClassifier<F>
type Fitted = FittedBaggingClassifier<F>
fit.Source§type Error = FerroError
type Error = FerroError
fit.Source§impl<F: Float + ToPrimitive + FromPrimitive + Send + Sync + 'static> PipelineEstimator<F> for BaggingClassifier<F>
impl<F: Float + ToPrimitive + FromPrimitive + Send + Sync + 'static> PipelineEstimator<F> for BaggingClassifier<F>
Source§fn fit_pipeline(
&self,
x: &Array2<F>,
y: &Array1<F>,
) -> Result<Box<dyn FittedPipelineEstimator<F>>, FerroError>
fn fit_pipeline( &self, x: &Array2<F>, y: &Array1<F>, ) -> Result<Box<dyn FittedPipelineEstimator<F>>, FerroError>
Auto Trait Implementations§
impl<F> Freeze for BaggingClassifier<F>
impl<F> RefUnwindSafe for BaggingClassifier<F>where
F: RefUnwindSafe,
impl<F> Send for BaggingClassifier<F>where
F: Send,
impl<F> Sync for BaggingClassifier<F>where
F: Sync,
impl<F> Unpin for BaggingClassifier<F>where
F: Unpin,
impl<F> UnsafeUnpin for BaggingClassifier<F>
impl<F> UnwindSafe for BaggingClassifier<F>where
F: 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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> DistributionExt for Twhere
T: ?Sized,
impl<T> DistributionExt for Twhere
T: ?Sized,
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