Skip to content

Instantly share code, notes, and snippets.

@chulman444
Created March 18, 2018 14:50
Show Gist options
  • Save chulman444/3930576fe6262520e938848323ffa385 to your computer and use it in GitHub Desktop.
Save chulman444/3930576fe6262520e938848323ffa385 to your computer and use it in GitHub Desktop.
import matplotlib.pyplot as plt
from sklearn.datasets import make_classification
from sklearn.decomposition import PCA
import numpy as np
X1, Y2 = make_classification(n_features=2, n_informative=2, n_redundant=0,
n_classes=1,
n_clusters_per_class=1)
x0 = X1[:,0]
y0 = X1[:,1]
plt.subplot(211)
plt.scatter(X1[:,0], X1[:,1])
M = np.column_stack((x0,y0))
pca = PCA(n_components=2)
pca.fit(M)
print(pca.explained_variance_)
print(pca.explained_variance_ratio_)
transformed = pca.transform(M)
print(len(transformed))
plt.subplot(212)
plt.scatter(transformed[:,0], transformed[:,1])
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment