Skip to content

Commit

Permalink
Add testing and result ss
Browse files Browse the repository at this point in the history
  • Loading branch information
ankit2001 committed May 23, 2020
1 parent 1d369cc commit 7a8976a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def fit(self, X):
evalues, evectors = np.linalg.eig(covariance)
evectors = evectors.T
indexes_maxi_k = np.argsort(evalues)[ : : -1]
evectors = evector[indexes_maxi_k]
evectors = evectors[indexes_maxi_k]
self.final_components = evectors[0 : self.reduced_to_k]

def transform(self, X):
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import numpy as np
import matplotlib.pyplot as plt
from sklearn import datasets
from PCA import PCA

pre_data = datasets.load_iris()
X = pre_data.data
Y = pre_data.target

pca = PCA(2)
pca.fit(X)
X_transformed = pca.transform(X)

print("Dimensions of X is " + str(X.shape))

print("Dimensions of X_transformed is" + str(X_transformed.shape))

print(Y)

x1 = X_transformed[: ,0]
x2 = X_transformed[: ,1]

plt.xlabel("Component 1")
plt.ylabel("Component 2")
plt.scatter(x1, x2, alpha = 1, cmap = plt.cm.get_cmap('Dark2', 3), c = Y, edgecolor = "red")
plt.colorbar()
plt.show()

0 comments on commit 7a8976a

Please sign in to comment.