Created
June 5, 2015 15:20
-
-
Save Mengyuz/b0eac658fe7d5fe52e62 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import scipy | |
import matplotlib.pyplot as plt | |
import sys | |
def compute_r_squared(data, predictions): | |
''' | |
In exercise 5, we calculated the R^2 value for you. But why don't you try and | |
and calculate the R^2 value yourself. | |
Given a list of original data points, and also a list of predicted data points, | |
write a function that will compute and return the coefficient of determination (R^2) | |
for this data. numpy.mean() and numpy.sum() might both be useful here, but | |
not necessary. | |
Documentation about numpy.mean() and numpy.sum() below: | |
http://docs.scipy.org/doc/numpy/reference/generated/numpy.mean.html | |
http://docs.scipy.org/doc/numpy/reference/generated/numpy.sum.html | |
''' | |
# your code here | |
r_squared = 1-np.sum((data-predictions)**2)/np.sum((data-np.mean(data))**2) | |
return r_squared |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment