pub struct VotingRegressor<F> {
pub max_depths: Vec<Option<usize>>,
pub min_samples_split: usize,
pub min_samples_leaf: usize,
/* private fields */
}Expand description
Voting ensemble regressor.
Trains multiple decision tree regressors with different hyperparameter configurations on the full dataset. Final predictions are the average across all trees.
Diversity is introduced by varying max_depth across the ensemble members.
If no explicit depths are provided, a default set of depths is used.
§Type Parameters
F: The floating-point type (f32orf64).
§Examples
use ferrolearn_tree::VotingRegressor;
use ferrolearn_core::{Fit, Predict};
use ndarray::{array, Array1, Array2};
let x = Array2::from_shape_vec((6, 2), vec![
1.0, 2.0, 2.0, 3.0, 3.0, 3.0,
5.0, 6.0, 6.0, 7.0, 7.0, 8.0,
]).unwrap();
let y = array![1.0, 2.0, 3.0, 5.0, 6.0, 7.0];
let model = VotingRegressor::<f64>::new()
.with_max_depths(vec![Some(2), Some(4), None]);
let fitted = model.fit(&x, &y).unwrap();
let preds = fitted.predict(&x).unwrap();
assert_eq!(preds.len(), 6);Fields§
§max_depths: Vec<Option<usize>>Maximum depth settings for each tree in the ensemble.
min_samples_split: usizeMinimum number of samples required to split an internal node.
min_samples_leaf: usizeMinimum number of samples required in a leaf node.
Implementations§
Source§impl<F: Float> VotingRegressor<F>
impl<F: Float> VotingRegressor<F>
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new VotingRegressor with default settings.
Defaults: max_depths = [Some(2), Some(4), Some(6), None],
min_samples_split = 2, min_samples_leaf = 1.
Sourcepub fn with_max_depths(self, max_depths: Vec<Option<usize>>) -> Self
pub fn with_max_depths(self, max_depths: Vec<Option<usize>>) -> Self
Set the maximum depth settings for each ensemble member.
Sourcepub fn with_min_samples_split(self, min_samples_split: usize) -> Self
pub fn with_min_samples_split(self, min_samples_split: usize) -> Self
Set the minimum number of samples required to split a node.
Sourcepub fn with_min_samples_leaf(self, min_samples_leaf: usize) -> Self
pub fn with_min_samples_leaf(self, min_samples_leaf: usize) -> Self
Set the minimum number of samples required in a leaf node.
Trait Implementations§
Source§impl<F: Clone> Clone for VotingRegressor<F>
impl<F: Clone> Clone for VotingRegressor<F>
Source§fn clone(&self) -> VotingRegressor<F>
fn clone(&self) -> VotingRegressor<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 VotingRegressor<F>
impl<F: Debug> Debug for VotingRegressor<F>
Source§impl<F: Float> Default for VotingRegressor<F>
impl<F: Float> Default for VotingRegressor<F>
Source§impl<'de, F> Deserialize<'de> for VotingRegressor<F>
impl<'de, F> Deserialize<'de> for VotingRegressor<F>
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl<F: Float + Send + Sync + 'static> Fit<ArrayBase<OwnedRepr<F>, Dim<[usize; 2]>>, ArrayBase<OwnedRepr<F>, Dim<[usize; 1]>>> for VotingRegressor<F>
impl<F: Float + Send + Sync + 'static> Fit<ArrayBase<OwnedRepr<F>, Dim<[usize; 2]>>, ArrayBase<OwnedRepr<F>, Dim<[usize; 1]>>> for VotingRegressor<F>
Source§fn fit(
&self,
x: &Array2<F>,
y: &Array1<F>,
) -> Result<FittedVotingRegressor<F>, FerroError>
fn fit( &self, x: &Array2<F>, y: &Array1<F>, ) -> Result<FittedVotingRegressor<F>, FerroError>
Fit the voting regressor by training each decision tree on the full dataset.
§Errors
Returns FerroError::ShapeMismatch if x and y have different
numbers of samples.
Returns FerroError::InsufficientSamples if there are no samples.
Returns FerroError::InvalidParameter if configuration is invalid.
Source§type Fitted = FittedVotingRegressor<F>
type Fitted = FittedVotingRegressor<F>
fit.Source§type Error = FerroError
type Error = FerroError
fit.Source§impl<F: Float + Send + Sync + 'static> PipelineEstimator<F> for VotingRegressor<F>
impl<F: Float + Send + Sync + 'static> PipelineEstimator<F> for VotingRegressor<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 VotingRegressor<F>
impl<F> RefUnwindSafe for VotingRegressor<F>where
F: RefUnwindSafe,
impl<F> Send for VotingRegressor<F>where
F: Send,
impl<F> Sync for VotingRegressor<F>where
F: Sync,
impl<F> Unpin for VotingRegressor<F>where
F: Unpin,
impl<F> UnsafeUnpin for VotingRegressor<F>
impl<F> UnwindSafe for VotingRegressor<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