Feature importance is a measure of how much each input feature contributes to a machine learning model's predictions. It helps answer questions such as:
- Which features are most influential?
- Which features can be removed without significantly affecting performance?
- Which features should receive more attention during feature engineering?
For example, suppose you are predicting house prices using the following features:
| Feature | Importance |
|---|---|
| Area | 0.48 |
| Location | 0.29 |
| Number of Bedrooms | 0.12 |
| Age of House | 0.08 |
| Parking Spaces | 0.03 |
This tells us that Area has the greatest influence on the predicted price, while Parking Spaces contributes very little.
Feature importance helps in:
- ✅ Understanding the model
- ✅ Removing irrelevant features
- ✅ Reducing overfitting
- ✅ Faster training
- ✅ Better feature engineering
- ✅ Explaining predictions to stakeholders
There is no single method. The appropriate method depends on the machine learning algorithm being used.
The methods can be broadly grouped into six categories.
- Model Coefficients
- Decision Tree Feature Importance
- Permutation Feature Importance
- SHAP (SHapley Additive exPlanations)
- LIME (Local Interpretable Model-agnostic Explanations)
- Mutual Information
Applicable to:
- Linear Regression
- Logistic Regression
- Ridge Regression
- Lasso Regression
A linear regression model is
y = β0 + β1x1 + β2x2 + … + βnxn
Each coefficient represents the influence of its feature.
Example:
Interpretation:
- Area coefficient = 120
- Bedrooms coefficient = 25000
- Age coefficient = −800
A larger absolute coefficient generally indicates greater importance.
- Very easy to interpret
- Fast
- Features should be scaled before comparing coefficients.
- Assumes linear relationships.
Applicable to:
- Decision Trees
- Random Forests
- Extra Trees
Decision trees split data using the feature that produces the largest reduction in impurity.
Common impurity measures include:
- Gini Index
- Entropy
- Variance Reduction (for regression)
The importance of a feature is calculated as the total impurity reduction contributed by all splits using that feature.
Income
├── Age
│ ├── Salary
│ └── Experience
└── Loan Amount
If Income is selected near the root and appears frequently, it is usually more important than the other features.
- Built into tree-based models
- Very fast
- Biased toward features with many unique values
- Can overestimate importance of continuous features
This is one of the most popular model-agnostic methods.
Idea
- Train the model.
- Measure baseline accuracy.
- Shuffle one feature.
- Measure accuracy again.
- The larger the performance drop, the more important the feature.
Original Accuracy:
95%
Shuffle Age:
Accuracy → 80%
Drop = 15%
Shuffle Income:
Accuracy → 94%
Drop = 1%
Therefore,
Age is much more important than Income.
- Works with any model
- Easy to understand
- Computationally expensive
- Can underestimate importance when features are highly correlated
SHAP is one of the most powerful methods for interpreting machine learning models.
It comes from game theory, where each feature is viewed as a "player" contributing to the prediction.
For every prediction,
Prediction = Base Value + ∑(SHAP Values)
Each feature receives a contribution value.
| Feature | SHAP Value |
|---|---|
| Income | +12 |
| Age | −4 |
| Experience | +8 |
Interpretation:
- Income increases the prediction by 12.
- Age decreases it by 4.
- Experience increases it by 8.
- Very accurate
- Explains individual predictions and global feature importance
- Works with almost all ML models
- Computationally intensive for large datasets
- More complex to understand than simpler methods
LIME explains one prediction at a time.
Instead of analysing the whole model, it:
- Chooses one observation.
- Creates many similar samples around it.
- Fits a simple interpretable model locally.
- Uses that local model to estimate feature importance.
Suppose a loan application is rejected.
LIME might report:
Income +35%
Credit Score +25%
Existing Loans -40%
Age +5%
This explains why that specific applicant received the prediction.
- Easy to understand
- Works with any model
- Explains only local behaviour
- Results may vary depending on the sampled neighbourhood
Mutual Information measures how much knowing one variable reduces uncertainty about another.
If a feature provides a lot of information about the target, it has high mutual information.
Suppose we are predicting whether a customer buys a product.
Income → strongly related
Age → weakly related
Favourite Colour → unrelated
The mutual information scores might be:
| Feature | MI Score |
|---|---|
| Income | 0.81 |
| Age | 0.22 |
| Favourite Colour | 0.01 |
- Captures non-linear relationships
- Does not assume linearity
- Does not indicate whether the relationship is positive or negative
- Does not explain interactions between features
| Method | Model-Specific | Works with Any Model | Explains Individual Predictions | Speed | Best For |
|---|---|---|---|---|---|
| Linear Coefficients | ✅ | ❌ | ❌ | Very Fast | Linear models |
| Tree Importance | ✅ | ❌ | ❌ | Fast | Decision Trees, Random Forests |
| Permutation Importance | ❌ | ✅ | ❌ | Medium | General-purpose feature ranking |
| SHAP | Mostly model-agnostic (specialized versions exist) | ✅ | ✅ | Slow | Detailed global and local explanations |
| LIME | ❌ | ✅ | ✅ | Medium | Explaining individual predictions |
| Mutual Information | ❌ | ✅ | ❌ | Fast | Feature selection before training |
| If you're using... | Recommended Method |
|---|---|
| Linear Regression | Coefficients (after feature scaling) |
| Logistic Regression | Coefficients (after feature scaling) |
| Decision Tree | Built-in tree feature importance |
| Random Forest | Built-in importance + Permutation Importance |
| XGBoost / LightGBM / CatBoost | Built-in importance + SHAP |
| Neural Networks | SHAP or Permutation Importance |
| Any black-box model | SHAP or LIME |
| Feature selection before modelling | Mutual Information or Permutation Importance |
- Feature importance quantifies how much each input feature influences a model's predictions.
- Different models require different interpretation techniques; there is no universally best method.
- Model coefficients are simple and effective for linear models.
- Tree-based importance is efficient but can be biased toward high-cardinality features.
- Permutation importance is model-agnostic and measures the effect of disrupting a feature on model performance.
- SHAP provides the most comprehensive explanations by attributing contributions to each feature for both global and individual predictions.
- LIME focuses on explaining a single prediction using a local surrogate model.
- Mutual Information is primarily a feature-selection technique that detects both linear and non-linear dependencies before or during model development.
- Drop-Column Feature Importance – Retrain the model after removing one feature at a time and measure the decrease in performance. This is accurate but computationally expensive.
- Information Gain – Often discussed for decision trees and closely related to impurity reduction (especially when entropy is used instead of Gini impurity).
- Gain, Cover, and Frequency Importance – Built-in importance measures used by gradient boosting libraries such as XGBoost and LightGBM.
- Recursive Feature Elimination (RFE) – An iterative feature selection method that removes the least important features based on a model.
- Boruta Algorithm – A wrapper method built around Random Forests that identifies all relevant features by comparing them with randomized "shadow" features.
No comments:
Post a Comment