Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b3188fb

Browse files
thomasjpfanjnothman
authored andcommitted
[MRG] BUG Fixes test_scale_and_stability in windows (#15661)
1 parent df681ad commit b3188fb

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

doc/whats_new/v0.22.rst

+4
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ random sampling procedures.
101101
- :class:`linear_model.Ridge` when `X` is sparse. |Fix|
102102
- :class:`model_selection.StratifiedKFold` and any use of `cv=int` with a
103103
classifier. |Fix|
104+
- :class:`cross_decomposition.CCA` when using scipy >= 1.3 |Fix|
104105

105106
Details are listed in the changelog below.
106107

@@ -209,6 +210,9 @@ Changelog
209210
``inverse_transform`` to transform data to the original space`.
210211
:pr:`15304` by :user:`Jaime Ferrando Huertas <jiwidi>`.
211212

213+
- |Fix| :class:`cross_decomposition.CCA` now produces the same results with
214+
scipy 1.3 and previous scipy versions. :pr:`15661` by `Thomas Fan`_.
215+
212216
:mod:`sklearn.datasets`
213217
.......................
214218

sklearn/cross_decomposition/_pls.py

+15-2
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,26 @@ def _nipals_twoblocks_inner_loop(X, Y, mode="A", max_iter=500, tol=1e-06,
4040
ite = 1
4141
X_pinv = Y_pinv = None
4242
eps = np.finfo(X.dtype).eps
43+
44+
if mode == "B":
45+
# Uses condition from scipy<1.3 in pinv2 which was changed in
46+
# https://github.com/scipy/scipy/pull/10067. In scipy 1.3, the
47+
# condition was changed to depend on the largest singular value
48+
X_t = X.dtype.char.lower()
49+
Y_t = Y.dtype.char.lower()
50+
factor = {'f': 1E3, 'd': 1E6}
51+
52+
cond_X = factor[X_t] * eps
53+
cond_Y = factor[Y_t] * eps
54+
4355
# Inner loop of the Wold algo.
4456
while True:
4557
# 1.1 Update u: the X weights
4658
if mode == "B":
4759
if X_pinv is None:
4860
# We use slower pinv2 (same as np.linalg.pinv) for stability
4961
# reasons
50-
X_pinv = pinv2(X, check_finite=False)
62+
X_pinv = pinv2(X, check_finite=False, cond=cond_X)
5163
x_weights = np.dot(X_pinv, y_score)
5264
else: # mode A
5365
# Mode A regress each X column on y_score
@@ -64,7 +76,8 @@ def _nipals_twoblocks_inner_loop(X, Y, mode="A", max_iter=500, tol=1e-06,
6476
# 2.1 Update y_weights
6577
if mode == "B":
6678
if Y_pinv is None:
67-
Y_pinv = pinv2(Y, check_finite=False) # compute once pinv(Y)
79+
# compute once pinv(Y)
80+
Y_pinv = pinv2(Y, check_finite=False, cond=cond_Y)
6881
y_weights = np.dot(Y_pinv, x_score)
6982
else:
7083
# Mode A regress each Y column on x_score

0 commit comments

Comments
 (0)