您的位置:首页 > 编程语言 > Python开发

Kernel principal component analysis in scikit-learn

2017-04-16 16:44 351 查看
For our convenience, scikit-learn implements a kernel PCA class in the sklearn.decomposition
submodule. The usage is similar to the standard PCA class, and we can specify the kernel via the
kernel parameter .

from sklearn.decomposition import KernelPCA
X, y = make_moons(n_samples=100, random_state=123)
scikit_kpca = KernelPCA(n_components=2, kernel='rbf', gamma=15)
X_skernpca = scikit_kpca.fit_transform(X)


Plot the transformed half-moon shape data onto the frst two principal components

plt.scatter(X_skernpca[y == 0, 0], X_skernpca[y == 0, 1],
color='red', marker='^', alpha=0.5)
plt.scatter(X_skernpca[y == 1, 0], X_skernpca[y == 1, 1],
color='blue', marker='o', alpha=0.5)
plt.xlabel('PC1')
plt.ylabel('PC2')
plt.show()




Reference:《Python Machine Learning》
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  machine-learning Python