0
$\begingroup$

This is my code, I calculated R square using Scikit learn :

y =[0, 10, 20, 30, 40] f =[0, 1, 2, 3, 4] r2 = r2_score(y, f) print('r2 score for perfect model is', r2) 

Output :

r2 score for perfect model is -1.4300000000000002 

Why is this coming out negative?

$\endgroup$
4
  • 1
    $\begingroup$ FAQ: stats.stackexchange.com/search?q=negative+r+square. $\endgroup$ Commented Sep 13, 2022 at 16:11
  • $\begingroup$ In order to point you to the specific parts of the duplicate that are pertinent to your particular confusion, why do you think the $R^2$ returned by your code should be $1?$ (You refer to a perfect model, so I assume you expect a perfect $R^2$.) $\endgroup$ Commented Sep 13, 2022 at 16:24
  • $\begingroup$ Yes, it's a perfect fit, so why am i getting a negative value? $\endgroup$ Commented Sep 13, 2022 at 16:30
  • $\begingroup$ How is it a perfect fit? Your observed value is 40, and you predict 4 (or maybe you observed 4 and predicted 40). // You might be interested in my simulations here and the paragraph right below the simulation code. $\endgroup$ Commented Sep 13, 2022 at 16:36

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.