You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

importance

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

importance

Permutation feature importance

0.0.5
latest
Source
npmnpm
Version published
Weekly downloads
16
6.67%
Maintainers
1
Weekly downloads
 
Created
Source

Permutation feature importance package for browsers and Node.js

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.

  • More info about the method: Permutation Feature Importance
  • Permutation importance can be biased if features are highly correlated (Hooker, Mentch 2019)

Usage

// Create and train a model first
const rf = new RandomForestRegressor({
  maxDepth: 20,
  nEstimators: 50
})
rf.train(X, y)

// Get feature importance
const imp = importance(rf, X, y, {
  kind: 'mse',
  n: 10,
  means: true,
  verbose: false
})
console.log(impsRF)

You can also check example.js in this repo that uses the random-forest package as a predictive model.

API

importance(model, X, y, options)
  • model - trained model with predict method (predictProba if cross-entropy used as score)
  • 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.
  • means - if true returns only average importance
  • verbose - if true throws some info into console

Feature selection

Feature importance is often used for variable selection. Permutation-based importance is a good method for that goal, but if you need more robust selection method check boruta.js

Web demo

The importance package is used for feature selection on StatSim Select and for data visualization on StatSim Vis

Keywords

ml

FAQs

Package last updated on 31 Jul 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts