79676733

Date: 2025-06-23 20:34:25
Score: 0.5
Natty:
Report link

I like the results of this code, which is a pure Matplotlib solution, using the so-called implicit API, which is most suitable for use with something like a Jupyter notebook.

# just to show the column names
data = data[['person_age', 'person_income', 'person_emp_length', 'loan_amnt', 'loan_int_rate', 'loan_percent_income', 'cb_person_cred_hist_length', 'loan_status']]

correlation = data.corr()

mask = numpy.triu(numpy.ones_like(correlation, dtype=bool))
correlation = correlation.mask(mask)
correlation.style.background_gradient()

plt.matshow(correlation, vmin=-1, vmax=1)
plt.colorbar()

plt.xticks(numpy.arange(len(correlation.columns)), correlation.columns, rotation=90)
plt.yticks(numpy.arange(len(correlation.columns)), correlation.columns)

for i in range(len(correlation.columns)):
    for j in range(len(correlation.columns)):
        value = correlation.iloc[i, j]
        if not numpy.isnan(value):
            plt.text(j, i, f"{value:.2f}", ha='center', va='center', color='black')

plt.savefig('correlation.pdf', bbox_inches='tight')
None # suppress junk output in Jupyter Notebook cell

It produces the following result:

Matplotlib correlation plot

Reasons:
  • Probably link only (1):
  • Long answer (-1):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: user28464084