关于 sklearn.decomposition.KernelPCA的简单介绍

from sklearn import decomposition
import numpy as np
A1_mean = [1, 1]
A1_cov = [[2, .99], [1, 1]]
A1 = np.random.multivariate_normal(A1_mean, A1_cov, 50)

A2_mean = [5, 5]
A2_cov = [[2, .99], [1, 1]]
A2 = np.random.multivariate_normal(A2_mean, A2_cov, 50)

A = np.vstack((A1, A2)) #A1:50*2;A2:50*2,水平连接

B_mean = [5, 0]
B_cov = [[.5, -1], [-0.9, .5]]
B = np.random.multivariate_normal(B_mean, B_cov, 100)

import matplotlib.pyplot as plt

plt.scatter(A[:,0],A[:,1],c='r',marker='o')
plt.scatter(B[:,0],B[:,1],c='g',marker='*')
plt.show()


#很蠢的想法,把A和B合并,然后进行一维可分
kpca = decomposition.KernelPCA(kernel='cosine', n_components=1)
AB = np.vstack((A, B))
AB_transformed = kpca.fit_transform(AB)
plt.scatter(AB_transformed,AB_transformed,c='b',marker='*')
plt.show()


kpca = decomposition.KernelPCA(n_components=1)
AB = np.vstack((A, B))
AB_transformed = kpca.fit_transform(AB)
plt.scatter(AB_transformed,AB_transformed,c='b',marker='*')
plt.show()

 

 

注意1:书上说consin PCA 比缺省的linear PCA要好,是不是consin PCA更紧致,数据不发散.

始终搞不懂什么时候用,什么时候不用

 

fit(X, y=None)
Fit the model from data in X.
ParametersX: array-like, shape (n_samples, n_features) :
Training vector, where n_samples in the number of samples and n_features is the numberof features.


fit_transform(X, y=None, **params)
Fit the model from data in X and transform X.
ParametersX: array-like, shape (n_samples, n_features) :
Training vector, where n_samples in the number of samples and n_features is the numberof features.

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值