Skip to content

Instantly share code, notes, and snippets.

@vaclavcadek
Created August 4, 2015 13:11
Show Gist options
  • Save vaclavcadek/d7cd3166b4d9fca409fe to your computer and use it in GitHub Desktop.
Save vaclavcadek/d7cd3166b4d9fca409fe to your computer and use it in GitHub Desktop.
Plot the correlation matrix (Spearman's) of values within the dataframe
import numpy as np
def plot_correlation(dataframe, title='', corr_type=''):
lang_names = dataframe.columns.tolist()
tick_indices = np.arange(0.5, len(lang_names) + 0.5)
plt.figure(figsize=(12,7))
plt.pcolor(dataframe.values, cmap='RdBu', vmin=-1, vmax=1)
colorbar = plt.colorbar()
colorbar.set_label(corr_type)
plt.title(title)
plt.xticks(tick_indices, lang_names, rotation='vertical')
plt.yticks(tick_indices, lang_names)
spearman_corr = data.corr(method='spearman')
plot_correlation(
spearman_corr,
title='Predictors Correlation',
corr_type='Spearman\'s Rank Correlation')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment