Skip to content

Philipp-Sc/importance

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Permutation feature importance

Feature selection

Feature importance is often used for variable selection.

Compute the relative importance of input variables of trained predictive models using feature shuffling

When called, the importance function shuffles each feature n times and computes the difference between the base score (calculated with original features X and target variable y) and permuted data. Intuitively that measures how the performance of a model decreases when we "remove" the feature.

Usage

importance = { git="https://github.com/philipp-sc/importance.git" }
    use importance::*;
    use importance::score::*;

    struct MockModel;

    impl Model for MockModel {
        fn predict(&self, x: &Vec<Vec<f64>>) -> Vec<f64> {
            x.iter().map(|x| x.iter().sum()).collect() // Mock predictions
        }
    }
 
    fn main() {
        let model = MockModel;
        let x = vec![vec![1.0, 0.0, 3.0], vec![4.0, 0.0, 6.0], vec![7.0, 0.0, 9.0]];
        let y = vec![4.0, 10.0, 16.0];

        let opts = Opts {
            verbose: true,
            kind: Some(ScoreKind::Smape),
            n: Some(100),
            only_means: true,
            scale: true,
        };

        let importances = importance(&model, x, y, opts);
        println!("Importances: {:?}", importances);
    }

API

importance(model, X, y, options)
  • model - trained model with predict method
  • X - 2D array of features
  • y - 1D array of target variables

Options:

  • kind - scoring function (mse, mae, rmse, smape, acc, ce (cross-entropy)
  • n - number of times each feature is shuffled.
  • only_means - if true returns only average importance
  • verbose - if true throws some info into console

About

Permutation feature importance

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages