text_plain_output_1.png
from scipy.linalg import eigh

from sklearn.preprocessing import StandardScaler

import matplotlib.pyplot as plt

import numpy as np

import numpy as np # linear algebra

import pandas as pd

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

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
d0 = pd.read_csv('../input/train.csv')

l = d0['label']
d = d0.drop('label', axis=1)

idx = 150
grid_data = d.iloc[idx].as_matrix().reshape(28, 28)

#Pick first 15k data-points to work on for time-efficiency.
#Exercise: Perform the same analysis on all of 42K data-point

labels = l.head(15000)
data = d.head(15000)

print("the shape of sample data = ", data.shape)

from sklearn.preprocessing import StandardScaler
standardized_data = StandardScaler().fit_transform(data)

sample_data = standardized_data
covar_matrix = np.matmul(sample_data.T, sample_data)

from scipy.linalg import eigh
values, vectors = eigh(covar_matrix, eigvals=(782, 783))
print('Shape of eigen vectors = ', vectors.shape)
vectors = vectors.T
print('Updated shape of eigen vectors =', vectors.shape)