MCPcopy Create free account
hub / github.com/lazyprogrammer/machine_learning_examples / get_r2

Function get_r2

linear_regression_class/systolic.py:41–49  ·  view source on GitHub ↗
(X, Y)

Source from the content-addressed store, hash-verified

39X3only = df[['X3', 'ones']]
40
41def get_r2(X, Y):
42 w = np.linalg.solve( X.T.dot(X), X.T.dot(Y) )
43 Yhat = X.dot(w)
44
45 # determine how good the model is by computing the r-squared
46 d1 = Y - Yhat
47 d2 = Y - Y.mean()
48 r2 = 1 - d1.dot(d1) / d2.dot(d2)
49 return r2
50
51print("r2 for x2 only:", get_r2(X2only, Y))
52print("r2 for x3 only:", get_r2(X3only, Y))

Callers 1

systolic.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected