Skip to main content

HoeffdingTreeClassifier

Struct HoeffdingTreeClassifier 

Source
pub struct HoeffdingTreeClassifier { /* private fields */ }
Available on crate feature alloc only.
Expand description

A streaming decision tree classifier based on the VFDT algorithm.

Grows incrementally by maintaining per-leaf class distributions and histogram bins. Splits are committed when the Hoeffding bound guarantees the best information-gain split is statistically superior to the runner-up.

§Thread Safety

HoeffdingTreeClassifier is Send + Sync, making it usable in async and multi-threaded pipelines.

Implementations§

Source§

impl HoeffdingTreeClassifier

Source

pub fn new(config: HoeffdingClassifierConfig) -> Self

Create a new classifier from the given configuration.

If config.n_features > 0, the tree is immediately initialized with a root leaf. Otherwise, initialization is deferred until the first training sample arrives.

Source

pub fn train_one(&mut self, features: &[f64], class: usize)

Train on a single observation: route to leaf, update stats, maybe split.

§Arguments
  • features – feature vector for this observation.
  • class – the class label (0-indexed).
Source

pub fn predict_class(&self, features: &[f64]) -> usize

Predict the majority class for the given feature vector.

Returns the class index with the highest count at the reached leaf. If no samples have been seen, returns 0.

Source

pub fn predict_proba(&self, features: &[f64]) -> Vec<f64>

Predict the class probability distribution for the given feature vector.

Returns a Vec<f64> of length n_classes where each entry is the estimated probability (fraction of samples) for that class. The probabilities sum to 1.0 (or all zeros if no samples seen).

Source

pub fn n_leaves(&self) -> usize

Number of leaf nodes in the tree.

Source

pub fn n_nodes(&self) -> usize

Total number of nodes (leaves + splits) in the tree.

Source

pub fn max_depth_seen(&self) -> usize

Maximum depth reached by any node in the tree.

Source

pub fn n_classes(&self) -> usize

Number of discovered classes.

Source

pub fn n_samples_seen(&self) -> u64

Total number of training samples seen since creation or last reset.

Source

pub fn reset(&mut self)

Reset the tree to its initial (untrained) state.

Clears all nodes and counters. If n_features was configured up front, the root leaf is re-created; otherwise initialization is deferred again.

Trait Implementations§

Source§

impl Clone for HoeffdingTreeClassifier

Source§

fn clone(&self) -> HoeffdingTreeClassifier

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for HoeffdingTreeClassifier

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl StreamingLearner for HoeffdingTreeClassifier

Source§

fn train_one(&mut self, features: &[f64], target: f64, _weight: f64)

Train on a single observation.

The target is cast to usize for the class label. Weight is currently unused (all samples contribute equally).

Source§

fn predict(&self, features: &[f64]) -> f64

Predict the majority class as a floating-point value.

Source§

fn n_samples_seen(&self) -> u64

Total number of observations trained on since creation or last reset.
Source§

fn reset(&mut self)

Reset the model to its initial (untrained) state. Read more
Source§

fn train(&mut self, features: &[f64], target: f64)

Train on a single observation with unit weight. Read more
Source§

fn predict_batch(&self, feature_matrix: &[&[f64]]) -> Vec<f64>

Predict for each row in a feature matrix. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.