sklearn.cross_decomposition.PLSCanonical?

class sklearn.cross_decomposition.PLSCanonical(n_components=2, *, scale=True, algorithm='nipals', max_iter=500, tol=1e-06, copy=True)

[源碼]

PLSCanonical實現了原始Wold算法的2塊規范PLS [Tenenhaus 1998] p.204,在[Wegelin 2000]中稱為PLS-C2A。

此類從PLS繼承,mode=“A”且deflation_mode =“ canonical”,norm_y_weights = True,algorithm =“ nipals”,只是svd會提供類似的結果,直至出現數值錯誤。

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

0.8版的新功能。

參數 說明
n_components int, (default 2)
要保留的組件數量
scale boolean, (default True)
scale數據選項
algorithm string, “nipals” or “svd”
用于估計權重的算法。 稱為n_components次,即外循環的每次迭代時執行一次。
max_iter an integer, (default 500)
NIPALS內循環的最大迭代次數(僅當algorithm =“ nipals”時使用)
tol non-negative real, default 1e-06
迭代算法中使用的容差
copy boolean, default True
是否應在副本上進行緊縮。 通常將默認值設為True,除非您不擔心副作用
屬性 說明
x_weights_ array, shape = [p, n_components]
X權重向量。
y_weights_ array, shape = [q, n_components]
Y權重向量。
x_loadings_ array, shape = [p, n_components]
X加載向量。
y_loadings_ array, shape = [q, n_components]
Y加載向量。
x_scores_ array, shape = [n_samples, n_components]
X得分。
y_scores_ array, shape = [n_samples, n_components]
Y得分。
x_rotations_ array, shape = [p, n_components]
X潛在旋轉。
y_rotations_ array, shape = [q, n_components]
Y潛在旋轉。
coef_ array of shape (p, q)
線性模型的系數:Y = X coef_ + Err
n_iter_ array-like
每個組件的NIPALS內部循環的迭代次數。 如果提供的算法是“ svd”,則不起作用。

另見:

矩陣:

T: x_scores_
U: y_scores_
W: x_weights_
C: y_weights_
P: x_loadings_
Q: y_loadings__

計算如下:

X = T P.T + Err and Y = U Q.T + Err
T[:, k] = Xk W[:, k] for k in range(n_components)
U[:, k] = Yk C[:, k] for k in range(n_components)
x_rotations_ = W (P.T W)^(-1)
y_rotations_ = C (Q.T C)^(-1)

其中Xk和Yk是迭代k的殘差矩陣。

講解PLS的幻燈片

對于每個分量k,找到優化的權重u,v:

max corr(Xk u, Yk v) * std(Xk u) std(Yk u), such that ``|u| = |v| = 1``

注意,它使得分和塊內方差之間的相關性最大化。

X(Xk + 1)塊的殘差矩陣是通過對當前X分數x_score的收縮獲得的。

Y(Yk + 1)塊的殘差矩陣是通過對當前Y分數進行收縮獲得的。 這將執行PLS回歸的規范對稱版本。 但與CCA略有不同。 這主要用于建模。

此實現使用函數plsca(X,Y)提供與R語言(R-project)中提供的“plspm”包相同的結果。 結果與“mixOmics”包的函數pls(...,mode ="canonical")相等或共線。不同之處在于,由于mixOmics實現未將y_weights歸一化,因此它并未完全實現Wold算法。

參考

Jacob A. Wegelin. A survey of Partial Least Squares (PLS) methods, with emphasis on the two-block case. Technical Report 371, Department of Statistics, University of Washington, Seattle, 2000.

Tenenhaus, M. (1998). La regression PLS: theorie et pratique. Paris: Editions Technic.

示例

>>> from sklearn.cross_decomposition import PLSCanonical
>>> X = [[0.0.1.], [1.,0.,0.], [2.,2.,2.], [2.,5.,4.]]
>>> Y = [[0.1-0.2], [0.91.1], [6.25.9], [11.912.3]]
>>> plsca = PLSCanonical(n_components=2)
>>> plsca.fit(X, Y)
PLSCanonical()
>>> X_c, Y_c = plsca.transform(X, Y)
方法 說明
fit(self, X, Y) 用模型訓練數據
fit_transform(self, X[, y]) 在訓練集上學習并應用降維
get_params(self[, deep]) 獲取評估器參數
inverse_transform(self, X) 將數據轉換回其原始空間。
predict(self, X[, copy]) (self, X[, copy])
score(self, X, y[, sample_weight]) 返回預測的確定系數R^2。
transform(self, X[, Y, copy]) 應用從訓練集學習到的降維
set_params(self, **params) 設置此估算器的參數。
__init__(self, n_components=2, *, scale=True, algorithm='nipals', max_iter=500, tol=1e-06, copy=True)

[源碼]

初始化self。 有關準確的簽名,請參見help(type(self))。

fit(self, X, Y)

[源碼]

應用在訓練集上學習的降維。

參數 說明
X array-like of shape (n_samples, n_features)
訓練向量,其中n_samples是樣本數,n_features是預測變量數。
y array-like of shape (n_samples, n_targets)
目標向量,其中n_samples是樣本數,n_targets是響應變量數。
返回值
如果未指定Y,則為x_scores,否則為(x_scores,y_scores)。
get_params(self, deep=True)

[源碼]

獲取此估計量的參數。

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

[源碼]

將數據轉換回其原始空間。

參數 說明
X array-like of shape (n_samples, n_components)
新數據,其中n_samples是樣本數,n_components是pls分量數。
返回值 說明
x_reconstructed array-like of shape (n_samples, n_features)

僅當n_components = n_features時,此轉換才是精確的

predict(self, X, copy=True)

[源碼]

應用在訓練集上學習到的降維

參數 說明
X array-like of shape (n_samples, n_features)
訓練向量,其中n_samples是樣本數,n_features是預測變量數。
copy boolean, default True
是復制X和Y,還是執行就地歸一化。

該調用需要估計p x q矩陣,這在高維空間中可能是個問題。

score(self, X, y, sample_weight=None)

[源碼]

返回預測的確定系數R^2。

系數R^2定義為(1-u/v),其中u是平方的殘差和((y_true-y_pred)** 2).sum(),而v是平方的總和((y_true- y_true.mean())** 2).sum()。 可能的最高得分為1.0,并且可能為負(因為該模型可能會更差)。 不管輸入特征如何,始終預測y的期望值的常數模型將獲得0.0的R^2分數。

參數 說明
X array-like of shape (n_samples, n_features)
測試樣本。對于某些估計量,可以是預先計算的內核矩陣或通用對象列表,shape =(n_samples,n_samples_fitted),其中n_samples_fitted是用于估計量擬合的樣本數。
y array-like of shape (n_samples,) or (n_samples, n_outputs)
X的真實值。
sample_weight array-like of shape (n_samples,), default=None
樣本權重
返回值 說明
score float
關于y的self.predict(X)的R^2。

用0.23版本multioutput ='uniform_average'在回歸器上調用score時,使用的R2得分,使之與r2_score的默認值保存一致。 這會影響所有多輸出回歸器的score方法(MultiOutputRegressor除外)。

set_params(self, **params)

[源碼]

設置此估算器的參數。

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

參數 說明
**params dict
估算器參數。
返回值 說明
self object
估算器實例。
transform(self, X, Y=None, copy=True)

[源碼]

應用在訓練集上學習到的降維。

參數 說明
X array-like of shape (n_samples, n_features)
訓練向量,其中n_samples是樣本數,n_features是預測變量數。
Y array-like of shape (n_samples, n_targets)
目標向量,其中n_samples是樣本數,n_targets是響應變量數。
copy boolean, default True
是復制X和Y,還是執行就地歸一化。
返回值說明
如果未指定Y,則為x_scores,否則為(x_scores,y_scores)。

sklearn.cross_decomposition.PLSCanonical使用示例?