0
0
ML Pythonml~20 mins

Model interpretability (SHAP, LIME) in ML Python - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Model Interpretability Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Understanding SHAP values
Which statement best describes what SHAP values represent in model interpretability?
ASHAP values show how much each feature contributes to pushing the model output from the average prediction to the current prediction.
BSHAP values are the raw input features used to train the model.
CSHAP values are the predicted probabilities of the model for each class.
DSHAP values are the weights of the neurons in a neural network.
Attempts:
2 left
💡 Hint
Think about how SHAP explains individual predictions by comparing to a baseline.
Predict Output
intermediate
2:00remaining
Output of LIME explanation code
What will be the output of the following Python code snippet using LIME for a binary classification model?
ML Python
import numpy as np
from sklearn.linear_model import LogisticRegression
from lime.lime_tabular import LimeTabularExplainer

X_train = np.array([[0,1],[1,1],[0,0],[1,0]])
y_train = np.array([0,1,0,1])
model = LogisticRegression().fit(X_train, y_train)

explainer = LimeTabularExplainer(X_train, feature_names=['f1','f2'], class_names=['class0','class1'], discretize_continuous=False)
exp = explainer.explain_instance(np.array([1,0]), model.predict_proba, num_features=2)
print(exp.as_list())
A[('f2 <= 0.5', 0.5), ('f1 > 0.5', 0.3)]
B[('f1', 0.5), ('f2', -0.1)]
C[('f1', 0.3), ('f2', 0.2)]
D[('f1 = 1', 0.4), ('f2 = 0', 0.6)]
Attempts:
2 left
💡 Hint
LIME returns feature contributions as tuples with feature name and weight.
Model Choice
advanced
1:30remaining
Choosing between SHAP and LIME
You want to explain predictions of a complex black-box model on tabular data with many features. Which method is best if you need consistent global and local explanations?
AUse LIME because it provides consistent global explanations for all features.
BUse LIME because it is faster and does not require retraining the model.
CUse SHAP because it provides consistent additive feature attributions for both local and global explanations.
DUse neither; use partial dependence plots instead.
Attempts:
2 left
💡 Hint
Consider which method has a solid theoretical foundation for consistent explanations.
Hyperparameter
advanced
1:30remaining
Effect of number of samples in LIME
In LIME, increasing the 'num_samples' parameter during explanation will most likely:
ADecrease explanation accuracy and increase speed.
BCause the model to retrain on more data.
CHave no effect on explanation quality or speed.
DIncrease explanation accuracy but increase computation time.
Attempts:
2 left
💡 Hint
Think about how sampling affects the local surrogate model fit.
🔧 Debug
expert
2:00remaining
Debugging SHAP value computation error
You run SHAP's TreeExplainer on a scikit-learn RandomForestClassifier but get the error: 'ValueError: Model output type not supported'. What is the most likely cause?
AYou used TreeExplainer on a model that is not tree-based.
BYou passed a multi-output regression model instead of classification.
CYou passed raw model predictions instead of probabilities to SHAP.
DYou did not convert the input data to a numpy array.
Attempts:
2 left
💡 Hint
Check if the model type matches the explainer requirements.