...
/Case Study: Local Explanations for Classification Problem
Case Study: Local Explanations for Classification Problem
Learn how to explain individual model decisions using the LIME framework for a classification case study.
In this lesson, we’ll build a predictive classification model on the loan approval dataset. We train a machine learning model to predict loan approval decisions. Then, we’ll explain the model prediction on individual examples using the LIME framework.
Train a classification model to predict loan approval decisions
Let’s use the credit loan dataset to train a machine learning model that predicts the propensity to approve loans.
The problem statement here is to predict the propensity to approve the loan, and we have a binary classification problem at hand.
from sklearn.ensemble import RandomForestClassifierfrom sklearn.model_selection import train_test_splitfrom sklearn.metrics import balanced_accuracy_score, roc_auc_scorefrom sklearn.metrics import confusion_matrixfrom sklearn.metrics import precision_score, recall_score# Create an instance of the random forest classifierclf = RandomForestClassifier()# Train the classifierclf.fit(X_train, y_train)# Make predictions on the test sety_pred = clf.predict(X_test)Y_pred_proba = clf.predict_proba(X_test)[:, 1]# Model performance metric# Compute the confusion matrixcm = confusion_matrix(y_test, y_pred)#print('\nConfusion Matrix:\n')print(cm)# Calculate precisionprecision = precision_score(y_test, y_pred)print("\nPrecision:", precision)# Calculate recallrecall = recall_score(y_test, y_pred)print("\Recall:", recall)# Calculate AUCprint('ROC AUC:',roc_auc_score(y_test, Y_pred_proba))
The code explanation is given below:
-
Lines 1–5: We import the necessary libraries required for ...