Model Explainability: LIME, SHAP, Feature Importance, and Metrics
What is model explainability, LIME and SHAP explained, feature importance charts, comparing models, and confusion matrix, ROC, and residual plots explained visually.
Model Explainability: LIME, SHAP, Feature Importance, and Metrics
Understanding why a model makes its predictions helps you trust it, debug it, and improve it. This guide covers LIME, SHAP, feature importance, and key evaluation visuals.
What Is Model Explainability?
Model explainability answers:
- Which features drove this prediction?
- How important is each feature overall?
- Why did the model choose class A instead of B?
LIME Explained
LIME (Local Interpretable Model-agnostic Explanations) explains a single prediction by fitting a simple model (e.g., linear) around that point.
How It Works
- Take one row (e.g., one customer).
- Create many slight variations of that row.
- Get the model's predictions for those variations.
- Fit a simple model (e.g., linear regression) to predict "model output" from "feature values."
- The coefficients of that simple model show which features mattered most for that prediction.
When to Use LIME
- Explain individual predictions (e.g., "Why did we reject this loan?")
- Works with any model (model-agnostic)
- Best for understanding a few important cases
SHAP Explained
SHAP (SHapley Additive exPlanations) assigns each feature a "contribution" to each prediction, based on game-theoretic Shapley values.
How It Works
- For each prediction, SHAP computes how much each feature added or subtracted from the base (average) prediction.
- Contributions sum to the difference between the actual prediction and the average.
- You get a consistent, theoretically grounded explanation per feature.
SHAP Values
- Positive – Feature pushed the prediction up (e.g., toward "Yes" or higher number).
- Negative – Feature pushed the prediction down.
- Magnitude – How strong the effect was.
When to Use SHAP
- Global feature importance (which features matter overall)
- Per-prediction explanations
- Comparing models
- More stable than LIME in many cases
Feature Importance Charts
Feature importance ranks features by how much they help the model (e.g., reduction in error or gain).
Bar Chart
- Each bar = one feature
- Height = importance (e.g., mean absolute SHAP, or tree-based gain)
- Longer bars = more important
What to Look For
- Top features are your main drivers.
- Long tail of small bars may be noise—consider dropping them.
- Compare importance across models to see if they agree.
Comparing Models
When you have multiple models (e.g., from AutoML), compare them by:
| Metric | What It Shows |
|---|---|
| Accuracy / F1 / RMSE | Overall performance |
| Feature importance | Do they use the same drivers? |
| SHAP summaries | Similar or different explanations? |
| Confusion matrix | Where do they make mistakes? |
| ROC curve | Trade-off between true positive rate and false positive rate |
Confusion Matrix Explained
A confusion matrix shows predicted vs actual labels for classification.
| Predicted: No | Predicted: Yes | |
|---|---|---|
| Actual: No | True Negative (TN) | False Positive (FP) |
| Actual: Yes | False Negative (FN) | True Positive (TP) |
What Each Cell Means
- True Positive: Correctly predicted Yes
- True Negative: Correctly predicted No
- False Positive: Predicted Yes, actually No (Type I error)
- False Negative: Predicted No, actually Yes (Type II error)
Derived Metrics
- Accuracy = (TP + TN) / Total
- Precision = TP / (TP + FP) — Of predicted Yes, how many were correct?
- Recall = TP / (TP + FN) — Of actual Yes, how many did we catch?
- F1 = 2 × (Precision × Recall) / (Precision + Recall)
ROC Curve Explained
The ROC curve (Receiver Operating Characteristic) plots:
- X-axis: False Positive Rate (FPR)
- Y-axis: True Positive Rate (TPR, recall)
AUC (Area Under Curve)
- AUC = 1.0 – Perfect classifier
- AUC = 0.5 – No better than random
- AUC between 0.8–1.0 – Good to excellent
Residual Plots Explained (Regression)
Residuals = Actual − Predicted.
What to Look For
| Pattern | Meaning |
|---|---|
| Random scatter | Good—errors are not systematic |
| Funnel shape | Heteroscedasticity—variance changes with prediction |
| Curve | Model is missing a pattern (e.g., non-linearity) |
| Outliers | A few points with large errors |
Common Plots
- Residuals vs Predicted: Check for patterns and heteroscedasticity
- Residuals vs Feature: See if one feature drives errors
- Histogram of residuals: Should look roughly normal if assumptions hold
Quick Reference
| Tool | Use For |
|---|---|
| LIME | Explain one prediction |
| SHAP | Global importance + per-prediction |
| Feature importance | Which features matter overall |
| Confusion matrix | Classification errors |
| ROC / AUC | Classification performance |
| Residual plots | Regression errors and patterns |
Related Articles
Machine Learning Overview: Workflow and Getting Started
A beginner-friendly recap of ML, classification vs regression vs clustering, the ML workflow (select, configure, train, evaluate, predict), and a 5-minute quick-start guide.
Using Saved Models for Predictions
How to use saved models for predictions: uploading new data, column mapping, manual prediction (entering values), model library, and downloading (pickle/ONNX/joblib).
ML Algorithms: All 15+ Explained in Plain English
Plain-English explanations of Linear/Ridge/Lasso/Elastic Net, Logistic Regression, Decision Tree, Random Forest, XGBoost, LightGBM, SVM, KNN, Naive Bayes, Neural Network, AdaBoost, Extra Trees—with pros, cons, and a comparison table.
Was this helpful?