pub struct DecisionTree<T, F>{ /* private fields */ }Expand description
Decision tree for regression and classification tasks with support for generic data types
Type parameters:
T- The type of the input features and target values (e.g., i32, u32, f64, or any custom type)F- The floating-point type used for internal calculations (typically f32 or f64)
Implementations§
Source§impl<T, F> DecisionTree<T, F>where
T: Clone + PartialOrd + Eq + Hash + Send + Sync + NumCast + ToPrimitive + Debug + AsPrimitive<F>,
F: Float + Send + Sync + NumCast + FromPrimitive + 'static + AsPrimitive<T>,
f64: AsPrimitive<F>,
usize: AsPrimitive<F>,
impl<T, F> DecisionTree<T, F>where
T: Clone + PartialOrd + Eq + Hash + Send + Sync + NumCast + ToPrimitive + Debug + AsPrimitive<F>,
F: Float + Send + Sync + NumCast + FromPrimitive + 'static + AsPrimitive<T>,
f64: AsPrimitive<F>,
usize: AsPrimitive<F>,
Sourcepub fn new(
tree_type: TreeType,
criterion: SplitCriterion,
max_depth: usize,
min_samples_split: usize,
min_samples_leaf: usize,
) -> Self
pub fn new( tree_type: TreeType, criterion: SplitCriterion, max_depth: usize, min_samples_split: usize, min_samples_leaf: usize, ) -> Self
Create a new decision tree
Sourcepub fn fit<D>(&mut self, features: &[Vec<D>], target: &[T]) -> StatsResult<()>where
D: Clone + PartialOrd + NumCast + ToPrimitive + AsPrimitive<F> + Send + Sync,
T: FromPrimitive,
pub fn fit<D>(&mut self, features: &[Vec<D>], target: &[T]) -> StatsResult<()>where
D: Clone + PartialOrd + NumCast + ToPrimitive + AsPrimitive<F> + Send + Sync,
T: FromPrimitive,
Train the decision tree on the given data
§Errors
Returns StatsError::EmptyData if features or target arrays are empty.
Returns StatsError::DimensionMismatch if features and target have different lengths.
Returns StatsError::InvalidInput if feature vectors have inconsistent lengths.
Returns StatsError::ConversionError if value conversion fails.
Sourcepub fn predict<D>(&self, features: &[Vec<D>]) -> StatsResult<Vec<T>>
pub fn predict<D>(&self, features: &[Vec<D>]) -> StatsResult<Vec<T>>
Make predictions for new data
§Errors
Returns StatsError::NotFitted if the tree has not been trained.
Returns StatsError::ConversionError if value conversion fails.
Sourcepub fn feature_importances(&self) -> Vec<F>
pub fn feature_importances(&self) -> Vec<F>
Get the importance of each feature
Sourcepub fn tree_structure(&self) -> String
pub fn tree_structure(&self) -> String
Get a textual representation of the tree structure
Source§impl<T, F> DecisionTree<T, F>where
T: Clone + PartialOrd + Eq + Hash + Send + Sync + NumCast + ToPrimitive + Debug + AsPrimitive<F>,
F: Float + Send + Sync + NumCast + FromPrimitive + 'static + AsPrimitive<T>,
f64: AsPrimitive<F>,
usize: AsPrimitive<F>,
Implementation of additional methods for enhanced usability
impl<T, F> DecisionTree<T, F>where
T: Clone + PartialOrd + Eq + Hash + Send + Sync + NumCast + ToPrimitive + Debug + AsPrimitive<F>,
F: Float + Send + Sync + NumCast + FromPrimitive + 'static + AsPrimitive<T>,
f64: AsPrimitive<F>,
usize: AsPrimitive<F>,
Implementation of additional methods for enhanced usability
Sourcepub fn get_max_depth(&self) -> usize
pub fn get_max_depth(&self) -> usize
Get the maximum depth of the tree
Sourcepub fn get_node_count(&self) -> usize
pub fn get_node_count(&self) -> usize
Get the number of nodes in the tree
Sourcepub fn is_trained(&self) -> bool
pub fn is_trained(&self) -> bool
Check if the tree has been trained
Sourcepub fn get_leaf_count(&self) -> usize
pub fn get_leaf_count(&self) -> usize
Get the number of leaf nodes in the tree
Sourcepub fn calculate_depth(&self) -> usize
pub fn calculate_depth(&self) -> usize
Calculate the actual depth of the tree
Trait Implementations§
Source§impl<T, F> Clone for DecisionTree<T, F>
impl<T, F> Clone for DecisionTree<T, F>
Source§fn clone(&self) -> DecisionTree<T, F>
fn clone(&self) -> DecisionTree<T, F>
1.0.0§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<T, F> Debug for DecisionTree<T, F>
impl<T, F> Debug for DecisionTree<T, F>
Auto Trait Implementations§
impl<T, F> Freeze for DecisionTree<T, F>
impl<T, F> RefUnwindSafe for DecisionTree<T, F>where
T: RefUnwindSafe,
F: RefUnwindSafe,
impl<T, F> Send for DecisionTree<T, F>
impl<T, F> Sync for DecisionTree<T, F>
impl<T, F> Unpin for DecisionTree<T, F>
impl<T, F> UnwindSafe for DecisionTree<T, F>where
T: UnwindSafe,
F: UnwindSafe,
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
clone_to_uninit)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