#[non_exhaustive]pub struct DecisionTreeClassifier { /* private fields */ }Expand description
CART decision tree for classification.
Implementations§
Source§impl DecisionTreeClassifier
impl DecisionTreeClassifier
Sourcepub fn min_samples_split(self, n: usize) -> Self
pub fn min_samples_split(self, n: usize) -> Self
Set minimum samples required to split an internal node.
Sourcepub fn min_samples_leaf(self, n: usize) -> Self
pub fn min_samples_leaf(self, n: usize) -> Self
Set minimum samples required in a leaf node.
Sourcepub fn max_features(self, n: usize) -> Self
pub fn max_features(self, n: usize) -> Self
Set maximum features to consider per split (for random forest).
Sourcepub fn criterion(self, c: SplitCriterion) -> Self
pub fn criterion(self, c: SplitCriterion) -> Self
Set the split criterion.
Sourcepub fn class_weight(self, cw: ClassWeight) -> Self
pub fn class_weight(self, cw: ClassWeight) -> Self
Set class weighting strategy for imbalanced datasets.
When set to ClassWeight::Balanced, minority classes receive
higher weight in impurity calculations, improving their recall.
§Example
use scry_learn::tree::DecisionTreeClassifier;
use scry_learn::weights::ClassWeight;
let dt = DecisionTreeClassifier::new()
.class_weight(ClassWeight::Balanced);Sourcepub fn ccp_alpha(self, alpha: f64) -> Self
pub fn ccp_alpha(self, alpha: f64) -> Self
Set cost-complexity pruning parameter.
Subtrees with effective alpha ≤ ccp_alpha are pruned after
tree construction. A value of 0.0 (default) disables pruning.
Larger values produce smaller, more regularized trees.
§Example
use scry_learn::tree::DecisionTreeClassifier;
let dt = DecisionTreeClassifier::new()
.ccp_alpha(0.01);Sourcepub fn predict(&self, features: &[Vec<f64>]) -> Result<Vec<f64>>
pub fn predict(&self, features: &[Vec<f64>]) -> Result<Vec<f64>>
Predict class labels for a feature matrix.
features is row-major: features[sample_idx][feature_idx].
Sourcepub fn predict_proba(&self, features: &[Vec<f64>]) -> Result<Vec<Vec<f64>>>
pub fn predict_proba(&self, features: &[Vec<f64>]) -> Result<Vec<Vec<f64>>>
Predict class probabilities for a feature matrix.
Sourcepub fn feature_importances(&self) -> Result<Vec<f64>>
pub fn feature_importances(&self) -> Result<Vec<f64>>
Get feature importances (sum of weighted impurity decreases).
Sourcepub fn n_features(&self) -> usize
pub fn n_features(&self) -> usize
Number of features the model was trained on.
Sourcepub fn cost_complexity_pruning_path(
&self,
data: &Dataset,
) -> Result<(Vec<f64>, Vec<f64>)>
pub fn cost_complexity_pruning_path( &self, data: &Dataset, ) -> Result<(Vec<f64>, Vec<f64>)>
Compute the cost-complexity pruning path for this classifier.
Trains an unpruned tree, then returns (ccp_alphas, total_impurities),
a sequence of effective alpha values and the corresponding total tree
impurity at each pruning step. Useful for selecting ccp_alpha via
the elbow method.
The classifier must be fitted before calling this method.
Trait Implementations§
Source§impl CalibrableClassifier for DecisionTreeClassifier
impl CalibrableClassifier for DecisionTreeClassifier
Source§impl Clone for DecisionTreeClassifier
impl Clone for DecisionTreeClassifier
Source§fn clone(&self) -> DecisionTreeClassifier
fn clone(&self) -> DecisionTreeClassifier
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Default for DecisionTreeClassifier
impl Default for DecisionTreeClassifier
Auto Trait Implementations§
impl Freeze for DecisionTreeClassifier
impl RefUnwindSafe for DecisionTreeClassifier
impl Send for DecisionTreeClassifier
impl Sync for DecisionTreeClassifier
impl Unpin for DecisionTreeClassifier
impl UnsafeUnpin for DecisionTreeClassifier
impl UnwindSafe for DecisionTreeClassifier
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> 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