import numpy as np
import matplotlib.pyplot as plt
from sklearn.decomposition import PCA
from sklearn import preprocessing
%matplotlib notebook
data = np.load("time-seriesPCAnew.npy")
X = np.column_stack((data[:,1], data[:,2], data[:,3], data[:,4], data[:,5]))
pca = PCA(n_components=5)
pca.fit(X)
print("explained variance:", pca.explained_variance_)
We should keep the two first components, there is a strong strength of association.
X_pca = pca.transform(X)
print("original shape : ", X.shape)
print("transformed shape :", X_pca.shape)
# do PCA and plot principal components
fig = plt.figure()
ax1 = fig.add_subplot(1,1,1)
ax1.plot(data[:,0],X_pca[:,1])
ax1.plot(data[:,0],X_pca[:,2])
plt.show()