8000 Deprecate residues_ in LinearRegression · scikit-learn/scikit-learn@76e0273 · GitHub
[go: up one dir, main page]

Skip to content

Commit 76e0273

Browse files
MaryanMorelamueller
authored andcommitted
Deprecate residues_ in LinearRegression
Residues can be empty if the rank of X does not satisfy the conditions described in scipy.linalg.lstsq documentation. As residues are not that useful (i.e. we're not doing stat testing), this property is deprecated and will be removed in sklearn 0.19.
1 parent 3382733 commit 76e0273

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

sklearn/linear_model/base.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
# Peter Prettenhofer <peter.prettenhofer@gmail.com>
1010
# Mathieu Blondel <mathieu@mblondel.org>
1111
# Lars Buitinck <L.J.Buitinck@uva.nl>
12+
# Maryan Morel <maryan.morel@polytechnique.edu>
1213
#
1314
# License: BSD 3 clause
1415

@@ -392,6 +393,12 @@ def __init__(self, fit_intercept=True, normalize=False, copy_X=True,
392393
self.copy_X = copy_X
393394
self.n_jobs = n_jobs
394395

396+
@property
397+
@deprecated("residues_ is deprecated and will be removed in 0.19")
398+
def residues_(self):
399+
"""Get the residues of the fitted model."""
400+
return self._residues
401+
395402
def fit(self, X, y, sample_weight=None):
396403
"""
397404
Fit linear model.
@@ -431,16 +438,16 @@ def fit(self, X, y, sample_weight=None):
431438
if y.ndim < 2:
432439
out = sparse_lsqr(X, y)
433440
self.coef_ = out[0]
434-
self.residues_ = out[3]
441+
self._residues = out[3]
435442
else:
436443
# sparse_lstsq cannot handle y with shape (M, K)
437444
outs = Parallel(n_jobs=n_jobs_)(
438445
delayed(sparse_lsqr)(X, y[:, j].ravel())
439446
for j in range(y.shape[1]))
440447
self.coef_ = np.vstack(out[0] for out in outs)
441-
self.residues_ = np.vstack(out[3] for out in outs)
448+
self._residues = np.vstack(out[3] for out in outs)
442449
else:
443-
self.coef_, self.residues_, self.rank_, self.singular_ = \
450+
self.coef_, self._residues, self.rank_, self.singular_ = \
444451
linalg.lstsq(X, y)
445452
self.coef_ = self.coef_.T
446453

0 commit comments

Comments
 (0)
0