Created
August 4, 2015 13:11
-
-
Save vaclavcadek/d7cd3166b4d9fca409fe to your computer and use it in GitHub Desktop.
Plot the correlation matrix (Spearman's) of values within the dataframe
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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