text_html_output_1.png
from sklearn.decomposition import PCA

from sklearn.manifold import TSNE

from sklearn.preprocessing import StandardScaler

import matplotlib.pyplot as plt

import numpy as np # linear algebra

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

import seaborn as sns

train = pd.read_csv('../input/train.csv')
test = pd.read_csv('../input/test.csv')

num_training = len(train.values)
num_testing = len(test.values)

y_train = np.array(train.pop('label').values)
x_train = np.array(train.values)
x_test = np.array(test.values)

x_train = x_train.reshape(num_training, 28, 28)
x_test = x_test.reshape(num_testing, 28, 28)

for i in range(66):
    plt.xticks([])
    plt.yticks([])
plt.tight_layout()

rawx = train.values[:1000]
from sklearn.preprocessing import StandardScaler
xscaled = StandardScaler().fit_transform(rawx)
from sklearn.manifold import TSNE
tsne = TSNE()
vis = tsne.fit_transform(xscaled)
vis = [{'X': vis[i][0], 'Y': vis[i][1], 'K': y_train[i]} for i in range(len(vis))]

sns.FacetGrid(pd.DataFrame.from_dict(vis), hue='K', size=8).map(plt.scatter, 'X', 'Y').add_legend()

from sklearn.decomposition import PCA
pca = PCA(n_components=5)
pca_ani = pca.fit_transform(xscaled)
xpca = pca_ani[:, 0]
ypca = pca_ani[:, 1]
vispca = [{'X': xpca[i], 'Y': ypca[i], 'K': y_train[i]} for i in range(len(xpca))]

sns.FacetGrid(pd.DataFrame.from_dict(vispca), hue='K', size=8).map(plt.scatter, 'X', 'Y').add_legend()