sklearn.decomposition.KernelPCA?

class sklearn.decomposition.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)

[源碼]

內核主成分分析(KPCA)

通過使用內核減少非線性維數(請參閱成對度量,近似關系和內核)。

用戶指南中閱讀更多內容。

參數 說明
n_components int, default=None
組件數。如果為None,則將保留所有非零分量。
kernel “linear” , “poly” , “rbf” ,“sigmoid” , “cosine” , “precomputed”
內核。默認值為“linear”。
gamma float, default=1/n_features
rbf,poly和Sigmoid內核的內核系數。被其他內核忽略。
degree int, default=3
多核度。被其他內核忽略。
coef0 float, default=1
poly核和sigmoid核中的獨立項。被其他內核忽略。
kernel_params mapping of string to any, default=None
作為可調用對象傳遞的內核的參數(關鍵字參數)和值。被其他內核忽略。
alpha int, default=1.0
嶺回歸的超參數,用于學習逆變換(當fit_inverse_transform = True時)。
fit_inverse_transform bool, default=False
了解非預計算內核的逆變換。(即學會找到一個點的原像)
eigen_solver string [‘auto’,’dense’,’arpack’], default=’auto’
選擇要使用的特征求解器。如果n_components遠小于訓練樣本的數量,則arpack可能比密集特征求解器更有效。
tol float, default=0
arpack的收斂容限。如果為0,則arpack將選擇最佳值。
max_iter int, default=None
arpack的最大迭代次數。如果為None,則arpack將選擇最佳值。
remove_zero_eig boolean, default=False
如果為True,則將刪除所有具有零特征值的分量,以使輸出中的分量數可能小于n_components(有時由于數字不穩定性甚至為零)。當n_components為None時,將忽略此參數,并刪除特征值為零的組件。
random_state int, RandomState instance, default=None
eigen_solver=='arpack'時使用。在多個函數調用之間傳遞int以獲得可重復的結果。請參閱詞匯表

版本0.18中的新功能。
copy_X boolean, default=True
如果為True,則模型將復制輸入X并將其存儲在X_fit_ 屬性中。如果對X不再做任何更改,則該設置copy_X=False將通過存儲引用來 節省內存。

版本0.18中的新功能。
n_jobs int or None, optional (default=None)
要運行的并行作業數。 None除非joblib.parallel_backend上下文中,否則表示1 。 -1表示使用所有處理器。有關 更多詳細信息,請參見詞匯表

版本0.18中的新功能。
屬性 說明
lambdas_ array, (n_components,)
中心核矩陣的特征值以降序排列。如果n_componentsremove_zero_eig均未設置,則將存儲所有值。
alphas_ array, (n_samples, n_components)
中心核矩陣的特征向量。如果n_componentsremove_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_為參考。此屬性用于進行轉換的調用。

參考文獻

  • 內核PCA引入于:

    Bernhard Schoelkopf, Alexander J. Smola, and Klaus-Robert Mueller. 1999. Kernel principal component analysis. In Advances in kernel methods, MIT Press, Cambridge, MA, USA 327-352.

例子

>>> from sklearn.datasets import load_digits
>>> from sklearn.decomposition import KernelPCA
>>> X, _ = load_digits(return_X_y=True)
>>> transformer = KernelPCA(n_components=7, kernel='linear')
>>> X_transformed = transformer.fit_transform(X)
>>> X_transformed.shape
(1797, 7)

方法

方法 說明
fit(X[, y]) 根據X中的數據擬合模型。
fit_transform(X[, y]) 根據X中的數據擬合模型并轉換X。
get_params([deep]) 獲取此估計量的參數。
inverse_transform(X) 將X轉換回原始空間。
set_params(**params) 設置此估算器的參數。
transform(X) 轉換X。
__init__(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)

[源碼]

初始化self。請參閱help(type(self))獲取準確的信息。

fit(X, y=None)

[源碼]

根據X中的數據擬合模型。

參數 說明
X array-like, shape (n_samples, n_features)
訓練向量,其中樣本數量為n_samples個,特征數量為n_features個。
返回值 說明
self object
返回實例本身。
fit_transform(X, y=None, **params)

[源碼]

根據X中的數據擬合模型并轉換X。

參數 說明
X array-like, shape (n_samples, n_features)
訓練向量,其中樣本數量為n_samples個,特征數量為n_features個。
返回值 說明
X_new array-like, shape (n_samples, n_components)
get_params(deep=True)

[源碼]

獲取此估計量的參數。

參數 說明
deep bool, default=True
如果為True,則將返回此估算器和其所包含子對象的參數。
返回值 說明
params mapping of string to any
參數名稱映射到其值。
inverse_transform(X )

[源碼]

將X轉換回原始空間。

參數 說明
X array-like, shape (n_samples, n_components)
返回值 說明
X_new array-like, shape (n_samples, n_features)

參考文獻

“Learning to Find Pre-Images”, G BakIr et al, 2004.

set_params(**params)

[源碼]

設置此估算器的參數。

該方法適用于簡單的估計器以及嵌套對象(例如管道)。后者具有<component>__<parameter>形式的參數, 以便可以更新嵌套對象的每個組件。

參數 說明
**params dict
估算器參數。
返回值 說明
self object
估算器實例。
transform(X )

[源碼]

轉換X。

參數 說明
X array-like, shape (n_samples, n_features)
返回值 說明
X_new array-like, shape (n_samples, n_components)

sklearn.decomposition.KernelPCA使用示例?