Unsupervised Learning ใน Python
Benjamin Wilson
Director of Research at lateral.io

PCA(n_components=2)samples = อาร์เรย์ของข้อมูลการวัด iris (4 ฟีเจอร์)species = รายการหมายเลขสายพันธุ์ irisfrom sklearn.decomposition import PCApca = PCA(n_components=2)pca.fit(samples)
PCA(n_components=2)
transformed = pca.transform(samples)
print(transformed.shape)
(150, 2)
import matplotlib.pyplot as plt
xs = transformed[:,0]
ys = transformed[:,1]
plt.scatter(xs, ys, c=species)
plt.show()


scipy.sparse.csr_matrix แทน NumPy array ได้csr_matrix เก็บเฉพาะค่าที่ไม่ใช่ศูนย์ (ประหยัดหน่วยความจำ!)
PCA ของ scikit-learn ไม่รองรับ csr_matrixTruncatedSVD ของ scikit-learn แทนfrom sklearn.decomposition import TruncatedSVD
model = TruncatedSVD(n_components=3)
model.fit(documents) # documents is csr_matrix
transformed = model.transform(documents)
Unsupervised Learning ใน Python