@@ -25,7 +25,7 @@ def _nipals_twoblocks_inner_loop(X, Y, mode="A", max_iter=500, tol=1e-06):
25
25
# Inner loop of the Wold algo.
26
26
while True :
27
27
# 1.1 Update u: the X weights
28
- if mode is "B" :
28
+ if mode == "B" :
29
29
if X_pinv is None :
30
30
X_pinv = linalg .pinv (X ) # compute once pinv(X)
31
31
u = np .dot (X_pinv , y_score )
@@ -38,7 +38,7 @@ def _nipals_twoblocks_inner_loop(X, Y, mode="A", max_iter=500, tol=1e-06):
38
38
x_score = np .dot (X , u )
39
39
40
40
# 2.1 Update v: the Y weights
41
- if mode is "B" :
41
+ if mode == "B" :
42
42
if Y_pinv is None :
43
43
Y_pinv = linalg .pinv (Y ) # compute once pinv(Y)
44
44
v = np .dot (Y_pinv , x_score )
@@ -95,16 +95,16 @@ def _center_scale_xy(X, Y, scale=True):
95
95
class _PLS (BaseEstimator ):
96
96
"""Partial Least Square (PLS)
97
97
98
- We use the therminology defined by [Wegelin et al. 2000].
98
+ We use the terminology defined by [Wegelin et al. 2000].
99
99
This implementation uses the PLS Wold 2 blocks algorithm or NIPALS which is
100
100
based on two nested loops:
101
- (i) The outer loop iterate over compoments .
101
+ (i) The outer loop iterate over components .
102
102
(ii) The inner loop estimates the loading vectors. This can be done
103
103
with two algo. (a) the inner loop of the original NIPALS algo or (b) a
104
104
SVD on residuals cross-covariance matrices.
105
105
106
106
This implementation provides:
107
- - PLS regression, ie., PLS 2 blocks, mode A, with asymetric deflation.
107
+ - PLS regression, ie., PLS 2 blocks, mode A, with asymmetric deflation.
108
108
A.k.a. PLS2, with multivariate response or PLS1 with univariate response.
109
109
- PLS canonical, ie., PLS 2 blocks, mode A, with symetric deflation.
110
110
- CCA, ie., PLS 2 blocks, mode B, with symetric deflation.
@@ -167,7 +167,7 @@ class _PLS(BaseEstimator):
167
167
Y block to latents rotations.
168
168
169
169
coefs: array, [p, q]
170
- The coeficients of the linear model: Y = X coefs + Err
170
+ The coefficients of the linear model: Y = X coefs + Err
171
171
172
172
References
173
173
----------
@@ -227,7 +227,7 @@ def fit(self, X, Y, **params):
227
227
'has %s' % (X .shape [0 ], Y .shape [0 ]))
228
228
if self .n_components < 1 or self .n_components > p :
229
229
raise ValueError ('invalid number of components' )
230
- if self .algorithm is "svd" and self .mode is "B" :
230
+ if self .algorithm == "svd" and self .mode == "B" :
231
231
raise ValueError ('Incompatible configuration: mode B is not '
232
232
'implemented with svd algorithm' )
233
233
if not self .deflation_mode in ["canonical" , "regression" ]:
@@ -250,12 +250,15 @@ def fit(self, X, Y, **params):
250
250
for k in xrange (self .n_components ):
251
251
#1) weights estimation (inner loop)
252
252
# -----------------------------------
253
- if self .algorithm is "nipals" :
253
+ if self .algorithm == "nipals" :
254
254
u , v = _nipals_twoblocks_inner_loop (
255
255
X = Xk , Y = Yk , mode = self .mode ,
256
256
max_iter = self .max_iter , tol = self .tol )
257
- if self .algorithm is "svd" :
257
+ elif self .algorithm == "svd" :
258
258
u , v = _svd_cross_product (X = Xk , Y = Yk )
259
+ else :
260
+ raise ValueError ("Got algorithm %s when only 'svd' "
261
+ "and 'nipals' are known" % self .algorithm )
259
262
# compute scores
260
263
x_score = np .dot (Xk , u )
261
264
y_score = np .dot (Yk , v )
@@ -273,11 +276,11 @@ def fit(self, X, Y, **params):
273
276
x_loadings = np .dot (Xk .T , x_score ) / np .dot (x_score .T , x_score )
274
277
# - substract rank-one approximations to obtain remainder matrix
275
278
Xk -= np .dot (x_score , x_loadings .T )
276
- if self .deflation_mode is "canonical" :
279
+ if self .deflation_mode == "canonical" :
277
280
# - regress Yk's on y_score, then substract rank-one approx.
278
281
y_loadings = np .dot (Yk .T , y_score ) / np .dot (y_score .T , y_score )
279
282
Yk -= np .dot (y_score , y_loadings .T )
280
- if self .deflation_mode is "regression" :
283
+ if self .deflation_mode == "regression" :
281
284
# - regress Yk's on x_score, then substract rank-one approx.
282
285
y_loadings = np .dot (Yk .T , x_score ) / np .dot (x_score .T , x_score )
283
286
Yk -= np .dot (x_score , y_loadings .T )
@@ -301,8 +304,8 @@ def fit(self, X, Y, **params):
301
304
else :
302
305
self .y_rotations_ = np .ones (1 )
303
306
304
- if True or self .deflation_mode is "regression" :
305
- # Estimate regression coeficient
307
+ if True or self .deflation_mode == "regression" :
308
+ # Estimate regression coefficient
306
309
# Regress Y on T
307
310
# Y = TQ' + Err,
308
311
# Then express in function of X
0 commit comments