0

I have datas in two lists. One with the real ones (observed) and one with the predicted ones.

I wanna put it in a graph to get something with the two lists with different colors and the line between them but I don't get how to put the line in the graph even after all my researches.

Here is what I want it to look like.

For now, here's my code that shows the two lists. I don't get where to place my r_squared variable.

from sklearn.metrics import r2_score
import matplotlib.pyplot as plt

observed = [1, 4, 9]
predicted = [1.2, 4.1, 8.7]

r_squared = r2_score(observed, predicted)

plt.plot(observed, 'o', predicted, 'o')
Simon F.-Smith
  • 781
  • 3
  • 8

1 Answers1

1

The R^2 value is the coefficient of determination and it tells you how well your predicted values match the observed values, see here for more info. There isn't anywhere to really place your r_squared variable besides printing it or displaying the value on the graph.

The line you see in the example graph represents an R^2 value of 1, i.e where the predicted values perfectly match the observations.

To draw this line you could just do

from sklearn.metrics import r2_score
import matplotlib.pyplot as plt

observed = [1, 4, 9]
predicted = [1.2, 4.1, 8.7]

r_squared = r2_score(observed, predicted)

plt.plot(observed, predicted, 'o')

x = range(10)
y = range(10)
plt.plot(x,y)
plt.show()

print(r_squared)
DCrowley
  • 31
  • 3