Created
May 18, 2019 22:30
-
-
Save ychennay/c7cf8812261620a3178694df92544c0d to your computer and use it in GitHub Desktop.
This file contains 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 seaborn as sns | |
corr = X.corr() | |
# randomly pick 30 of the interest columns to drop to make the visualization more readable | |
drops = np.random.choice(X.filter(regex=('interest_1?[0-9]{2}')).columns, | |
size=30, replace=False) | |
corr = corr.loc[~corr.index.isin(drops)] | |
corr.drop(columns=drops, inplace=True) | |
# Generate a mask for the upper triangle | |
mask = np.zeros_like(corr, dtype=np.bool) | |
mask[np.triu_indices_from(mask)] = True | |
# Set up the matplotlib figure | |
f, ax = plt.subplots(figsize=(11, 9)) | |
# Generate a custom diverging colormap | |
cmap = sns.diverging_palette(220, 10, as_cmap=True) | |
# Draw the heatmap with the mask and correct aspect ratio | |
sns.heatmap(corr, mask=mask, cmap=cmap, vmax=.3, center=0, annot=True, | |
square=True, linewidths=.5, cbar_kws={"shrink": .5}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment