Unsupervised Learning bằng Python
Benjamin Wilson
Director of Research at lateral.io

PCA(n_components=2)samples = mảng đo đạc iris (4 đặc trưng)species = danh sách mã loài 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 thay cho mảng NumPycsr_matrix chỉ lưu các ô khác 0 (tiết kiệm bộ nhớ)
PCA của scikit-learn không hỗ trợ csr_matrixTruncatedSVD của scikit-learn thay thếfrom sklearn.decomposition import TruncatedSVD
model = TruncatedSVD(n_components=3)
model.fit(documents) # documents is csr_matrix
transformed = model.transform(documents)
Unsupervised Learning bằng Python