title: Significant mismatch between `r2_score` of `scikit-learn` and the R^2 calculation
body: <h1>Question</h1>
  
  <p>Why is there a significant difference between the <a href="http://scikit-learn.org/stable/modules/generated/sklearn.metrics.r2_score.html#sklearn.metrics.r2_score" rel="noreferrer"><code>r2_score</code> function in scikit-learn</a> and the formula for the <a href="https://en.wikipedia.org/wiki/Coefficient_of_determination" rel="noreferrer">Coefficient of Determination as described in Wikipedia</a>?  Which is the correct one?</p>
  
  <p><br /></p>
  
  <h1>Context</h1>
  
  <p>I'm using  with Python 3.5 to predict linear and quadratic models, and one of the measures of goodness of fit that I'm trying out is the .  However, while testing, there's a marked difference between the <code>r2_score</code> metric in <code>scikit-learn</code> and the calculation provided in Wikipedia.</p>
  
  <p><br /></p>
  
  <h1>Code</h1>
  
  <p>I'm providing my code here as reference, which computes the example in the Wikipedia page linked above.</p>
  
  <pre>
  from sklearn.metrics import r2_score
  import numpy
  
  y = [1, 2, 3, 4, 5]
  f = [1.9, 3.7, 5.8, 8.0, 9.6]
  
  # Convert to numpy array and ensure double precision to avoid single precision errors
  observed = numpy.array(y, dtype=numpy.float64)
  predicted = numpy.array(f, dtype=numpy.float64)
  
  scipy_value = r2_score(observed, predicted)
  
  >>> scipy_value: 
  </pre>
  
  <p>As is evident, the <code>scipy</code> calculated value is <code>-3.8699999999999992</code>while the reference value in Wikipedia is <code>0.998</code>.</p>
  
  <p>Thank you!</p>
  
  <p><strong>UPDATE:</strong> This is different from <a href="https://stackoverflow.com/q/23309073/1663942">this question about how R^2 is calculated in scikit-learn</a> as what I'm trying to understand and have clarified is the discrepancy between both results.  That question states that the formula used in scikit is the same as Wikipedia's which should not result in different values.</p>
  
  <p><strong>UPDATE #2:</strong> It turns out I made a mistake reading the Wikipedia article's example. Answers and comments below mention that the example I provide is for the linear, least squares fit of the (x, y) values in the example. For that, the answer in Wikipedia's article is correct. For that, the R^2 calue provided is 0.998. For the R^2 between both vectors, scikit's answer is also correct. Thanks a lot for your help!</p>