Timeline for Negative R2 on Simple Linear Regression (with intercept)
Current License: CC BY-SA 4.0
10 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Jun 2, 2023 at 11:19 | comment | added | Sextus Empiricus |
@JeanLescut The scipy.linalg.lstsq() has the same problems, but is just performing better and will make the 'error' less easily. I could make it fail with an online compiler onecompiler.com/python/3zadf7u39 (I believe that the link will take you to my scribble, although I am not sure whether it can change)
|
|
Jun 2, 2023 at 11:12 | comment | added | Jean Lescut | Absolutely agree with you. As I wrote below, my next step would be to ask for said warning to be implemented. Despite all my trials, I couldnt make lstsq() fail on my side. I'll keep investigating. Thank you so much for your help (for me and the community !) | |
Jun 2, 2023 at 10:37 | comment | added | Sextus Empiricus |
@JeanLescut I also had slightly different behaviour with lstsq() and changed the random seed. In your case does it also 'work' when you use np.random.seed(15) ? And even when it works, the cause of the problem (not giving an error for problematic user input) has not been resolved. Ideally the function should give a warning when results are computationally unstable.
|
|
Jun 2, 2023 at 9:01 | comment | added | Jean Lescut | You are absolutely right about CPU thing. According to my experiments, scipy.lstsq() doesnt lead to a negative R2 though. But the LinearRegression() code of sklearn convert X into a F-contiguous array before multiplying it with the parameters. This induces several small "errors" that actually becomes crazily bad in my case. I will investigate deeper and maybe propose a change in the sklearn code to keep arrays C-contiguous all along | |
Jun 2, 2023 at 8:37 | history | edited | Sextus Empiricus | CC BY-SA 4.0 |
added 1106 characters in body
|
Jun 2, 2023 at 8:32 | history | edited | Sextus Empiricus | CC BY-SA 4.0 |
added 1106 characters in body
|
Jun 2, 2023 at 7:25 | comment | added | Sextus Empiricus |
@JeanLescut I know that lm in R would provide an error telling that the matrix is singular. I recently encountered a similar question for MATLAB that had different behaviours with a similar issue of matrix inversion. stats.stackexchange.com/questions/616591
|
|
Jun 2, 2023 at 6:56 | comment | added | Jean Lescut | Amazing, we're getting closer ! My hope here is to try to implement a check in lstsq() and issue a warning when needed. It's understandable that the function fails, but not that it fails silently... | |
Jun 1, 2023 at 23:59 | history | edited | Sextus Empiricus | CC BY-SA 4.0 |
added 37 characters in body
|
Jun 1, 2023 at 23:52 | history | answered | Sextus Empiricus | CC BY-SA 4.0 |