DEV Community

Cover image for Interpreting Loan Predictions with TrustyAI: Part 3
Sohini Pattanayak for TrustyCore

Posted on • Originally published at dev.to

Interpreting Loan Predictions with TrustyAI: Part 3

Implementing Visualizations

Hello again, dear readers! In our previous sessions, we understood LIME explanations in TrustyAI and implemented a simple linear model to explain loan approvals. While seeing the saliency values of each feature is insightful, a graphical representation can offer a clearer understanding of model decisions. Let's delve deeper!

Creating a LIME Feature Impact Visualization

Before we begin, ensure you've gone through Part 2 of our series.

1. Setting Up:

Ensure you've imported the necessary libraries:

import matplotlib.pyplot as plt
Enter fullscreen mode Exit fullscreen mode

2. Generating LIME Explanations:

Using the TrustyAI library, generate the LIME explanations for your model as shown in the previous tutorial.

3. Visualizing Feature Impact:

Each feature's impact can be visualized as a bar in a bar chart. The height (positive or negative) indicates the magnitude of influence, and the color (blue for positive, red for negative, and green for the most influential) signifies the nature of the impact.

# Transform the explanation to a dataframe and sort by saliency
    exp_df = lime_explanation['output-0'].sort_values(by="Saliency")
Enter fullscreen mode Exit fullscreen mode

4. Extract feature names and their saliencies

 y_axis = list(exp_df['Saliency'])
    x_axis = ["Annual Income", "Number of Open Accounts", "Late Payments", "Debt-to-Income Ratio", "Credit Inquiries"]

    # Color-coding bars
    colors = ["green" if value == max(y_axis) else "blue" if value > 0 else "red" for value in y_axis]

    # Plotting
    fig, ax = plt.subplots()
    ax.set_facecolor("#f2f2f2")
    ax.bar(x_axis, y_axis, color=colors)
    plt.title('LIME: Feature Impact on Loan Approval Decision')
    plt.xticks(rotation=45, ha='right')
    plt.axhline(0, color="black")  # x-axis line
    plt.show()
Enter fullscreen mode Exit fullscreen mode

And there you go!

Image description

Like the blog? Do hit a Like, send me some unicorns, and don't forget to share it with your friends!

Thank you!

Top comments (2)

Collapse
 
michaeltharrington profile image
Michael Tharrington

Super cool stuff, Sohini!

Appreciate you sharing this series on TrustyAI... it seems like a really cool app you're building. 🙌

Collapse
 
sohinip profile image
Sohini Pattanayak

Hey hey! Thanks so much Michael :)