title: How to display R-squared value on my graph in Python
body: <p>I am a Python beginner so this may be more obvious than what I'm thinking. I'm using <code>Matplotlib</code> to graphically present my predicted data vs actual data via a neural network.
  I am able to calculate r-squared, and plot my data, but now I want to combine the value on the graph itself, which changes with every new run.</p>
  
  <p>My NN uses at least 4 different inputs, and gives one output. This is my end code for that:</p>
  
  <pre class="lang-py prettyprint-override"><code>y_predicted = model.predict(X_test)
  </code></pre>
  
  <p>This is how i calculate R2:</p>
  
  <pre class="lang-py prettyprint-override"><code># Using sklearn
  from sklearn.metrics import r2_score
  print r2_score(y_test, y_predicted)
  </code></pre>
  
  <p>and this is my graph:</p>
  
  <pre class="lang-py prettyprint-override"><code>fig, ax = plt.subplots()
  ax.scatter(y_test, y_predicted)
  ax.plot([y.min(), y.max()], [y.min(), y.max()], 'k--', lw=4)
  ax.set_xlabel('Actual')
  ax.set_ylabel('Predicted')
  #regression line
  y_test, y_predicted = y_test.reshape(-1,1), y_predicted.reshape(-1,1)
  ax.plot(y_test, LinearRegression().fit(y_test, y_predicted).predict(y_test))
  
  plt.show()
  </code></pre>
  
  <p>It gives something like the graph attached, and the R2 varies everytime I change the epochs, or number of layers, or type of data etc. The red is my line of regression, which I will label later.
  Since R2 is a function I can't simply use the legend or text code.</p>
  
  <p>I would also like to display MSE.</p>
  
  <p>Can anyone help me out?</p>
  
  <p><a href="https://i.stack.imgur.com/UGjBD.png" rel="noreferrer">Graph</a></p>