Skip to content

Instantly share code, notes, and snippets.

@RyotaBannai
Last active December 19, 2018 17:57
Show Gist options
  • Save RyotaBannai/d3667b9ce34ab91df43bcdc0000b7046 to your computer and use it in GitHub Desktop.
Save RyotaBannai/d3667b9ce34ab91df43bcdc0000b7046 to your computer and use it in GitHub Desktop.
import seaborn as sns
sns.set()
sns.despine(left=True)
fig, axes = plt.subplots(2, 2, figsize=(15, 10), gridspec_kw=dict(hspace=.4, wspace=.3))
title_settings={'fontsize':16}
subtitles=['Inversed samples with {} components']*3
# Plot Heatmap 1
ax = sns.heatmap(digits.data, cbar=False, ax=axes[0, 0])
ax.set_title('Original samples', **title_settings)
# Plot Heatmap 2, 3, and 4
plot_ind=[[0,1],[1,0],[1,1]]
n_components=[2,20,40]
for nc, title, i in zip(n_components, subtitles, plot_ind):
pca = PCA(n_components=nc)
PC = pca.fit_transform(digits.data)
inversed = pca.inverse_transform(PC)
ax = sns.heatmap(inversed, cbar=False, ax=axes[i[0],i[1]])
ax.set_title(title.format(nc), **title_settings)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment