from sklearn.decomposition import KernelPCA
KernelPCA(n_components=None, *, kernel='linear', gamma=None, degree=3, coef0=1, kernel_params=None, alpha=1.0, fit_inverse_transform=False, eigen_solver='auto', tol=0, max_iter=None, remove_zero_eig=False, random_state=None, copy_X=True, n_jobs=None)
参数说明:
1、n_components,主成分个数,未指定的话,全部非零主成分均会保留
2、kernel,选择的核函数,有"linear" | “poly” | “rbf” | “sigmoid” | “cosine” | “precomputed”
3、gamma,浮点类型,默认值为default=1/n_features,此参数若选择的核函数是rbf, poly and sigmoid kernels时有效,其他核函数则请忽略
4、degree : int, default=3。Degree for poly kernels. Ignored by other kernels.
属性 | 说明 |
---|---|
lambdas_ | array, (n_components,)中心核矩阵的特征值以降序排列。如果n_components和remove_zero_eig均未设置,则将存储所有值。 |
alphas_ | array, (n_samples, n_components)中心核矩阵的特征向量。如果n_components和 remove_zero_eig均未设置,则将存储所有组件。 |
dual_coef_ | array, (n_samples, n_features)逆变换矩阵。仅当fit_inverse_transform为True 时可用 。 |
X_transformed_fit_ | array, (n_samples, n_components)拟合数据在内核主成分上的投影。仅当fit_inverse_transform为True 时可用。 |
X_fit_ | (n_samples, n_features)用于拟合模型的数据。如果为copy_X=False,则X_fit_为参考。此属性用于进行转换的调用。 |
.fit()
根据X中的数据拟合模型。
| fit(self, X, y=None)
| Fit the model from data in X.
|
| Parameters
| ----------
| X : array-like, shape (n_samples, n_features)
| Training vector, where n_samples in the number of samples
| and n_features is the number of features.
|
| Returns
| -------
| self : object
| Returns the instance itself.
.fit_transform()
根据X中的数据拟合模型并转换X。
| fit_transform(self, X, y=None, **params)
| Fit the model from data in X and transform X.
|
| Parameters
| ----------
| X : array-like, shape (n_samples, n_features)
| Training vector, where n_samples in the number of samples
| and n_features is the number of features.
|
| Returns
| -------
| X_new : array-like, shape (n_samples, n_components)
.inverse_transform()
将X转换回原始空间。
| inverse_transform(self, X)
| Transform X back to original space.
|
| Parameters
| ----------
| X : array-like, shape (n_samples, n_components)
|
| Returns
| -------
| X_new : array-like, shape (n_samples, n_features)
.transform()
转换X。
| transform(self, X)
| Transform X.
|
| Parameters
| ----------
| X : array-like, shape (n_samples, n_features)
|
| Returns
| -------
| X_new : array-like, shape (n_samples, n_components)