Scikit-learn

Feature Importance

Compute feature importance for any model (can be classifier or regressor). This approach compute score for original data. Then it shuffle each feature and compute the change in the score. The featuers that after shuffling change the score the most are the most important. This method can be used with any predictive model that implements Scikit-learn API.

metricaccuracy

Required packages

You need below packages to use the code generated by recipe. All packages are automatically installed in MLJAR Studio.

scikit-learn>=1.5.0

matplotlib>=3.8.4

Interactive recipe

You can use below interactive recipe to generate code. This recipe is available in MLJAR Studio.

In the below recipe, we assume that you have following variables available in your notebook:

  • X (type DataFrame)
  • y (type Series)
  • my_classifier (type DecisionTreeClassifier)
  • my_regressor (type DecisionTreeRegressor)

Python code

# Python code will be here

Code explanation

  1. Compute permutation importance for features.
  2. Display results in matplotlib horizontal bar.

This step can be time consuming in case of large data or complex algorithm that has large prediction time.