text_plain_output_1.png image_output_1.png
from sklearn import decomposition

import matplotlib.pyplot as plt

import numpy as np

import pandas as pd

import seaborn as sns

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

label = data['label']
pixels = data.drop('label', axis=1)

from sklearn import decomposition
pca = decomposition.PCA()
pca.n_components = 2

pca_data = pca.fit_transform(pixels)
label = np.reshape(label.values, (label.shape[0], 1))

data_transformed = np.hstack((pca_data, label))
dframe = pd.DataFrame(data=data_transformed, columns=('pc1', 'pc2', 'label'))

sns.FacetGrid(dframe, hue='label', size=5).map(plt.scatter, 'pc1', 'pc2').add_legend()