#均方误差MSE
pp=predict.reshape(-1)
error = []
for i in range(len(test_labels)):
error.append(test_labels[i] - pp[i])
squaredError = []
absError = []
for val in error:
squaredError.append(val * val)#target-prediction之差平方
print("MSE = ", sum(squaredError) / len(squaredError))#均方误差MSE
#相关系数
def mean(x):
return sum(x) / len(x)
mean_a = mean(pp)
mean_b = mean(test_labels)
# 计算每一项数据与均值的差
def de_mean(x):
x_bar = mean(x)
return [x_i - x_bar for x_i in x]
# 辅助计算函数 dot product 、sum_of_squares
def dot(v, w):
return sum(v_i * w_i for v_i, w_i in zip(v, w))
def sum_of_squares(v):
return dot(v, v)
# 方差
def variance(x):
n = len(x)
deviations = de_mean(x)
return sum_of_squares(deviations) / (n - 1)
# 标准差
import math