top of page
Writer's pictureSohini Pattanayak

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.


Setting Up:

Ensure you've imported the necessary libraries:

Python
import matplotlib.pyplot as plt

Generating LIME Explanations:

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

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")

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()

Interpreting the Visualization

The resulting graph portrays the impact of each feature on the model's decision. Bars above the baseline show features that positively impact the decision, and those below signify negative influence. The green bar indicates the most influential feature for the given decision.


For instance, if the "Annual Income" bar stretches upwards and is green, it means that this feature has the highest positive influence on a loan approval decision for the given data point.


Wrapping Up


Visualizations empower us to explain complex machine learning models to stakeholders with varying technical expertise. By leveraging TrustyAI and its visualization capabilities, we make AI more transparent, fostering trust in the decisions it makes.


Stay tuned for more deep dives into the world of TrustyAI. Happy coding!


15 views0 comments

Kommentare


bottom of page