8000 Ravel coefficients instead of reshaping · scikit-learn/scikit-learn@a9579c2 · GitHub
[go: up one dir, main page]

Skip to content

Commit a9579c2

Browse files
committed
Ravel coefficients instead of reshaping
1 parent bb40fd2 commit a9579c2

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

sklearn/linear_model/_base.py

Lines changed: 5 additions & 1 deletion
< 5B5C tr class="diff-line-row">
Original file line numberDiff line numberDiff line change
@@ -546,8 +546,10 @@ def rmatvec(b):
546546
elif (X.shape[1] <= 2
547547
and np.all(np.linalg.eigvals(np.dot(X, np.transpose(X))) > 0)):
548548
n_samples, n_features = X.shape
549+
ravel = False
549550
if y.ndim == 1:
550551
y = y.reshape(-1, 1)
552+
ravel = True
551553
n_samples_, n_targets = y.shape
552554
alpha = np.asarray(0, dtype=X.dtype).ravel()
553555
if alpha.size not in [1, n_targets]:
@@ -574,7 +576,9 @@ def rmatvec(b):
574576
except linalg.LinAlgError:
575577
# use SVD solver if matrix is singular
576578
self.coef_ = _solve_svd(X, y, alpha)
577-
self.coef_ = self.coef_.reshape((self.coef_.shape[1],))
579+
if ravel:
580+
# When y was passed as a 1d-array, we flatten the coefficients.
581+
self.coef_ = self.coef_.ravel()
578582
else:
579583
self.coef_, self._residues, self.rank_, self.singular_ = \
580584
linalg.lstsq(X, y, check_finite=False)

0 commit comments

Comments
 (0)
0