0
$\begingroup$

I have a mulitvariate regression model that for which I'd like to see the residuals. I attempted to output the model's residuals via

model.residues_

But this has been deprecated. Any workarounds?

$\endgroup$
4
  • 3
    $\begingroup$ Compute them? y - model.predict(X)? $\endgroup$ Jul 26, 2017 at 20:04
  • 1
    $\begingroup$ I deleted a duplicate answer of this one; but wanted to note also that model.residues_ returns RSS, not residuals. If you wanted the former, you coudl use np.linalg.norm(y - model.predict(X)) ** 2. $\endgroup$
    – Kevin
    Jul 26, 2017 at 20:06
  • $\begingroup$ @Kevin Since mine was just a comment, I think you're fine to state that as an actual answer. $\endgroup$ Jul 26, 2017 at 20:07
  • $\begingroup$ There are saved in the object as ._residues so no need to recompute it again. $\endgroup$
    – Xbel
    Dec 12, 2019 at 13:26

1 Answer 1

3
$\begingroup$

This should be in StackOverflow (probably), but here's a quick workaround:

lm = LinearRegression().fit(X, y)

np.linalg.norm(y - lm.predict(X)) ** 2  #RSS, which is what lm.residues_ returns
$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.