-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpca.py
More file actions
28 lines (22 loc) · 713 Bytes
/
pca.py
File metadata and controls
28 lines (22 loc) · 713 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from sklearn.decomposition import PCA
import load_data
import numpy as np
"""Using PCA(principle component analisys) to reduce the dimensions of data"""
#loading mnist data
x_scaled, y = load_data.fetch_data()
#separating training and testing datas
train_x = x_scaled[:60000, :]
train_y = y[:60000]
test_x = x_scaled[60000:, :]
test_y = y[60000:]
#creating a pca object
pca = PCA(.95) #0.95 percentage of information will be preserved.
pca.fit(train_x)
#resampling the data to new dimensions
train_x = pca.transform(train_x)
test_x = pca.transform(test_x)
#saving processed data into .npy file
np.save('train_x', train_x )
np.save('train_y', train_y )
np.save('test_x', test_x)
np.save('test_y', test_y)