Skip to content

Commit cd98c55

Browse files
add r-squared
1 parent 6c6f60e commit cd98c55

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

linear_regression_class/lr_1d.py

+6
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,9 @@
3535
plt.scatter(X, Y)
3636
plt.plot(X, Yhat)
3737
plt.show()
38+
39+
# determine how good the model is by computing the r-squared
40+
d1 = Y - Yhat
41+
d2 = Y - Y.mean()
42+
r2 = 1 - d1.dot(d1) / d2.dot(d2)
43+
print "the r-squared is:", r2

0 commit comments

Comments
 (0)