0
0
ML Pythonml~10 mins

Model interpretability (SHAP, LIME) in ML Python - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the SHAP library.

ML Python
import [1]
Drag options to blanks, or click blank then click option'
Ashap
Blime
Csklearn
Dpandas
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to import 'lime' instead of 'shap'.
Importing unrelated libraries like 'pandas' or 'sklearn'.
2fill in blank
medium

Complete the code to create a LIME explainer for tabular data.

ML Python
from lime import lime_tabular
explainer = lime_tabular.LimeTabularExplainer([1], feature_names=feature_names, class_names=class_names, mode='classification')
Drag options to blanks, or click blank then click option'
Ay_train
BX_train
Cmodel
DX_test
Attempts:
3 left
💡 Hint
Common Mistakes
Passing labels (y_train) instead of features.
Passing the model object instead of data.
3fill in blank
hard

Fix the error in the SHAP values calculation code.

ML Python
explainer = shap.TreeExplainer(model)
shap_values = explainer.[1](X_test)
Drag options to blanks, or click blank then click option'
Ashap_values
Bexplain
Ccalculate
Dtransform
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-existent methods like 'transform' or 'calculate'.
Trying to call 'explain' which is not a method here.
4fill in blank
hard

Fill both blanks to create a dictionary of feature importances from SHAP values.

ML Python
feature_importance = {feature: abs(shap_values[[1]][i]) for i, feature in enumerate([2])}
Drag options to blanks, or click blank then click option'
A0
B1
Cfeature_names
DX_test
Attempts:
3 left
💡 Hint
Common Mistakes
Using index 1 which may correspond to another class.
Using raw data X_test instead of feature names.
5fill in blank
hard

Fill all three blanks to generate a LIME explanation and show the predicted class.

ML Python
exp = explainer.explain_instance([1], model.predict_proba, num_features=[2])
predicted_class = model.predict([[3]])[0]
Drag options to blanks, or click blank then click option'
AX_test[0]
B5
DX_train[0]
Attempts:
3 left
💡 Hint
Common Mistakes
Using training data instead of test data for explanation.
Passing wrong number of features to show.