pub struct FeatureImportance { /* private fields */ }Expand description
Tracks per-feature importance via accumulated split gains.
Each time a tree splits on a feature, the gain from that split is added to the feature’s running total. This produces a simple but effective measure of feature importance for gradient boosted trees.
§Example
use irithyll::metrics::FeatureImportance;
let mut fi = FeatureImportance::new(3);
fi.update(0, 1.5);
fi.update(2, 0.8);
fi.update(0, 0.3);
let top = fi.top_k(2);
assert_eq!(top[0].0, 0); // feature 0 has highest gainImplementations§
Source§impl FeatureImportance
impl FeatureImportance
Sourcepub fn new(n_features: usize) -> Self
pub fn new(n_features: usize) -> Self
Create a new tracker for n_features features, all initialized to zero.
Sourcepub fn importances(&self) -> &[f64]
pub fn importances(&self) -> &[f64]
Raw accumulated gains for all features.
Sourcepub fn normalized(&self) -> Vec<f64>
pub fn normalized(&self) -> Vec<f64>
Importances normalized to sum to 1.0.
Returns a vector of zeros if total accumulated gain is zero.
Sourcepub fn top_k(&self, k: usize) -> Vec<(usize, f64)>
pub fn top_k(&self, k: usize) -> Vec<(usize, f64)>
Top-k features by accumulated gain, sorted descending.
Returns (feature_index, gain) pairs. If k > n_features,
all features are returned.
Sourcepub fn n_features(&self) -> usize
pub fn n_features(&self) -> usize
Number of features being tracked.
Sourcepub fn total_gain(&self) -> f64
pub fn total_gain(&self) -> f64
Total accumulated gain across all features.
Trait Implementations§
Source§impl Clone for FeatureImportance
impl Clone for FeatureImportance
Source§fn clone(&self) -> FeatureImportance
fn clone(&self) -> FeatureImportance
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for FeatureImportance
impl RefUnwindSafe for FeatureImportance
impl Send for FeatureImportance
impl Sync for FeatureImportance
impl Unpin for FeatureImportance
impl UnsafeUnpin for FeatureImportance
impl UnwindSafe for FeatureImportance
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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>
Converts
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>
Converts
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