【发布时间】:2019-04-26 15:55:03
【问题描述】:
我是在解释维基百科上的这些公式吗 (https://en.wikipedia.org/wiki/Coefficient_of_determination) Python中的错误?以下是我尝试过的。
def ss_res(X, y, theta):
y_diff=[]
y_pred = X.dot(theta)
for i in range(0, len(y)):
y_diff.append((y[i]-y_pred[i])**2)
return np.sum(y_diff)
输出看起来正确,但数字略有偏差......像几个小数点。
def std_error(X, y, theta):
delta = (1/(len(y)-X.shape[1]+1))*(ss_res(X,y,theta))
matrix1=matrix_power((X.T.dot(X)),-1)
thing2=delta*matrix1
thing3=scipy.linalg.sqrtm(thing2)
res=np.diag(thing3)
serr=np.reshape(res, (6, 1))
return serr
std_error_array=std_error(X,y,theta)
【问题讨论】:
-
有点不对劲,
thing1是什么? -
抱歉 - 第一件事是 delta。已编辑
标签: python linear-regression linear-algebra