回归模型的score得分为负_sklearn之计算回归模型的四大评价指标(explained_variance_score、mean_absolute_error、mean_squared_error...

def calPerformance(y_true,y_pred):

'''

模型效果指标评估

y_true:真实的数据值

y_pred:回归模型预测的数据值

explained_variance_score:解释回归模型的方差得分,其值取值范围是[0,1],越接近于1说明自变量越能解释因变量

的方差变化,值越小则说明效果越差。

mean_absolute_error:平均绝对误差(Mean Absolute Error,MAE),用于评估预测结果和真实数据集的接近程度的程度

,其其值越小说明拟合效果越好。

mean_squared_error:均方差(Mean squared error,MSE),该指标计算的是拟合数据和原始数据对应样本点的误差的

平方和的均值,其值越小说明拟合效果越好。

r2_score:判定系数,其含义是也是解释回归模型的方差得分,其值取值范围是[0,1],越接近于1说明自变量越能解释因

变量的方差变化,值越小则说明效果越差。

'''

model_metrics_name=[explained_variance_score, mean_absolute_error, mean_squared_error, r2_score]

tmp_list=[]

for one in model_metrics_name:

tmp_score=one(y_true,y_pred)

tmp_list.append(tmp_score)

x=[]

x.append(tmp_list)

f1 = pd.DataFrame(x,columns=['explained_variance_score', 'mean_absolute_error', 'mean_squared_error', 'r2_score'])

print(f1)

return tmp_list

if __name__=='__main__':

y_pred=[22, 21, 21, 21, 22, 26, 28, 28, 33, 41, 93, 112, 119, 132, 126, 120, 101, 56, 58, 58, 57, 57, 53, 52, 52, 51, 50, 49, 49, 50, 54, 58, 85, 115, 125, 131, 135, 137, 135, 126, 109, 80, 83, 83, 77, 75, 74, 73, 73, 69, 67, 64, 64, 65, 69, 72, 93, 126, 141, 145, 126, 107, 65, 67, 70, 73, 77, 80, 82, 82, 79, 77, 72, 69, 67, 65, 64, 67, 75, 88, 105, 107, 101, 102, 100, 84, 85, 56, 50, 44, 41, 40, 36, 36, 35, 35, 34, 37, 37, 37, 38, 40, 41, 41, 44, 74, 98, 89, 89, 95, 101, 117, 115, 75, 47, 41, 40, 40, 37, 38, 40, 37, 37, 42, 41, 43, 39, 40, 44, 47, 54, 59, 70, 83, 83, 77, 58, 48, 50, 47, 44, 43, 42, 42, 41, 39, 39, 39, 40, 40, 40, 40, 44, 46, 46, 47, 45, 44, 43, 38, 34, 32, 32, 36, 35, 33, 34, 33, 29, 29, 30, 29, 28, 27, 25, 24, 23, 22, 23, 22, 25, 27, 25, 24, 22, 26, 30, 32, 34, 35, 34, 34, 36, 35, 36, 35, 37, 41, 40, 40, 44, 52, 74, 79, 75, 67, 49, 46, 40, 42, 40, 42, 44, 44, 46, 45, 44, 44, 42, 44, 45, 45, 46, 48, 72, 100, 101, 106, 104, 106, 78, 53, 51, 51, 52, 53, 53, 54, 58, 58, 59, 58, 58, 60, 59, 57, 56, 57, 98, 106, 114, 119, 114, 92, 52, 46, 42, 40, 40, 35, 35, 35, 33, 32, 33, 36, 40, 46, 54, 59, 74, 117, 132, 138, 122, 102, 93, 65, 44, 42, 40, 38, 39, 39, 38, 39, 39, 41, 41, 43, 46, 51, 53, 53, 54, 51, 52, 49, 45, 45, 45, 42, 40, 41, 45, 49, 54, 53, 53, 52, 52, 52, 52, 51, 51, 53, 55, 56, 55, 52, 52, 50, 48, 45, 43, 43, 47, 49, 46, 44, 49, 52, 53, 55, 58, 59, 60, 60, 61, 65, 71, 73, 73, 106, 115, 111, 100, 104, 106, 95, 54, 53, 54, 58, 56, 54, 55, 54, 53, 54, 56, 58, 60, 63, 61, 56, 57, 64, 102, 112, 117, 122, 120, 114, 111, 75, 48, 39, 40, 41, 40, 38, 39, 39, 41, 44, 42, 46, 45, 40, 41, 39, 37, 32, 32, 27, 27, 25, 23, 21, 20, 18, 18, 18, 17, 14, 15, 15, 16, 16, 14, 13, 18, 23, 23, 32, 29, 45, 45, 43, 49, 47, 45, 39, 35, 32, 26, 23, 20, 19, 21, 23, 22, 24, 25, 28, 26, 25, 29, 30, 30, 32, 30, 30, 32, 33, 34, 33, 33, 32, 31, 30, 30, 29, 28, 28, 27, 28, 28, 30, 29, 30, 32, 33, 29, 28, 36, 36, 40, 42, 41, 42, 41, 39, 32, 34, 32, 33, 36, 40, 38, 42, 43, 44, 46, 46, 51, 50, 49, 48, 46, 40, 36, 36, 31, 27, 24, 23, 21, 18, 19, 17, 16, 15, 16, 14, 13, 13, 13, 15, 20, 23, 25, 31, 29, 29, 27, 30, 29, 19, 21, 23, 25, 28, 29, 28, 28, 31, 30, 32, 35, 33, 30, 30, 33, 33, 32, 33, 36, 36, 34, 31, 30, 29, 28, 28, 28, 19, 18, 17, 18, 17, 18, 19, 20, 21, 20, 25, 28, 30, 29, 29, 28, 26, 24, 22, 23, 22, 22, 24, 22, 23, 25, 23, 22, 23, 21, 25, 27, 30, 29, 32, 46, 73, 90, 73, 77, 54, 51, 46, 46, 47, 49, 47, 45, 42, 43, 41, 36, 35, 33, 32, 36, 41, 48, 51, 55, 55, 56, 73, 80, 68, 59, 59, 56, 59, 64, 59, 55, 48, 29, 30, 32, 30, 30, 32, 35, 29, 29, 32, 44, 52, 53, 52, 52, 46, 42, 38, 33, 30, 32, 32, 35, 34, 36, 39, 42, 39, 45, 48, 48, 42, 47, 52, 54, 54, 54, 49, 53, 55, 50, 49, 47, 46, 43, 43, 51, 49, 51, 50, 51, 52, 53, 52, 53, 73, 82, 88, 100, 83, 89, 103, 110, 110, 106, 79, 63, 68, 55, 50, 47, 50, 54, 58, 59, 58, 51, 41, 38, 37, 40, 40, 40, 47, 51, 51, 49, 50, 48, 46, 43, 43, 42, 42, 41, 39, 42, 42, 38, 38, 36, 33, 33, 34, 33, 34, 36, 35, 29, 28, 30, 34, 37, 42, 44, 47, 48, 51, 52, 52, 50, 44, 43, 44, 41, 37, 34, 34, 30, 30, 34, 28, 27, 25, 26, 25, 23, 22, 23, 23, 24, 23, 24, 26, 28, 29, 28, 26, 26, 26, 27, 27, 28, 28, 26, 29, 30, 28, 28, 25, 22, 22, 22, 20, 20, 20, 20, 21, 26, 24, 24, 24, 26, 31, 33, 35, 35, 34, 33, 30, 30, 28, 29, 28, 26, 25, 23, 22, 23, 23, 22, 22, 26, 26, 26, 25, 27, 34, 37, 39, 41, 38, 35, 34, 35, 37, 38, 35, 30, 26, 24, 23, 21, 19, 21, 23, 22, 21, 21, 24, 24, 28, 35, 36, 35, 35, 32, 27, 36, 39, 38, 38, 30, 32, 30, 29, 26, 24, 21, 21, 23, 23, 23, 23, 24, 26, 30, 35, 39, 38, 35, 34, 48, 52, 42, 35, 34, 35, 38, 36, 34, 33, 33, 35, 37, 30, 29, 33, 37, 39, 40, 37, 38, 41, 43, 49, 53, 56, 56, 40, 38, 35, 35, 36, 36, 36, 38, 41, 45, 41, 36, 39, 40, 36, 34, 35, 36, 36, 36, 35, 37, 37, 39, 38, 40, 42, 46, 51, 54, 59, 62, 64, 65, 79, 88, 79, 72, 70, 68, 67, 58, 58, 59, 60, 62, 62, 62, 61, 63, 63, 62, 63, 65, 67, 69, 70, 69, 108, 118, 123, 122, 127, 129, 129, 114, 79, 70, 67, 70, 71, 71, 71, 72, 73, 73, 75, 76, 78, 81, 79, 78, 105, 113, 116, 109, 107, 90, 90, 94, 102, 105, 95, 94, 90, 80, 82, 77, 64, 52, 49]

y_true=[23, 23, 23, 22, 23, 26, 28, 28, 32, 37, 56, 64, 68, 74, 75, 71, 66, 55, 59, 59, 58, 58, 52, 51, 50, 49, 48, 47, 47, 48, 53, 59, 73, 83, 84, 86, 87, 90, 90, 88, 84, 78, 83, 83, 77, 75, 75, 73, 73, 69, 66, 64, 65, 68, 72, 77, 84, 96, 100, 102, 92, 79, 65, 66, 71, 75, 79, 82, 84, 84, 82, 79, 73, 70, 68, 65, 66, 70, 79, 93, 98, 85, 77, 76, 76, 72, 74, 57, 48, 44, 41, 40, 37, 36, 36, 35, 35, 37, 37, 37, 37, 39, 40, 40, 41, 53, 63, 60, 61, 64, 70, 84, 86, 66, 47, 41, 40, 40, 38, 39, 40, 38, 37, 41, 40, 42, 39, 40, 43, 46, 47, 47, 49, 56, 58, 56, 51, 47, 48, 46, 43, 42, 42, 41, 40, 39, 39, 39, 40, 40, 39, 40, 43, 44, 42, 42, 43, 43, 42, 38, 35, 33, 33, 37, 36, 34, 34, 34, 31, 31, 32, 31, 30, 29, 27, 26, 26, 25, 25, 24, 25, 25, 25, 24, 24, 28, 31, 33, 34, 35, 34, 34, 36, 35, 36, 35, 37, 40, 40, 40, 42, 45, 53, 54, 53, 52, 48, 46, 41, 43, 41, 42, 44, 44, 45, 44, 43, 43, 41, 43, 44, 43, 45, 46, 55, 65, 66, 71, 72, 73, 63, 52, 50, 50, 51, 52, 52, 53, 58, 58, 58, 57, 57, 59, 58, 57, 56, 56, 70, 71, 73, 76, 78, 70, 52, 45, 43, 41, 41, 36, 35, 35, 34, 33, 33, 36, 39, 44, 52, 59, 69, 88, 91, 96, 85, 70, 65, 54, 44, 42, 40, 38, 39, 39, 38, 39, 39, 40, 40, 42, 44, 48, 51, 51, 52, 49, 48, 44, 41, 42, 42, 41, 40, 41, 44, 47, 53, 52, 52, 51, 51, 51, 51, 50, 50, 52, 55, 57, 55, 51, 47, 44, 43, 42, 42, 42, 46, 47, 45, 43, 47, 51, 52, 55, 59, 61, 62, 61, 63, 68, 77, 79, 76, 84, 84, 80, 71, 72, 73, 70, 53, 52, 54, 59, 56, 54, 55, 53, 52, 54, 57, 59, 61, 66, 63, 57, 58, 64, 80, 86, 89, 91, 92, 90, 88, 70, 48, 39, 41, 42, 41, 39, 40, 40, 41, 43, 42, 45, 44, 40, 41, 39, 38, 34, 33, 29, 29, 27, 25, 24, 23, 21, 21, 21, 20, 17, 18, 18, 19, 19, 17, 16, 19, 22, 23, 33, 28, 41, 38, 40, 48, 45, 45, 40, 34, 31, 28, 25, 23, 22, 23, 25, 24, 26, 27, 29, 27, 26, 29, 30, 30, 32, 30, 30, 32, 33, 33, 32, 32, 32, 31, 30, 30, 29, 28, 28, 27, 28, 28, 29, 29, 30, 31, 32, 29, 29, 36, 36, 39, 40, 39, 40, 39, 38, 33, 34, 33, 33, 35, 38, 37, 40, 41, 42, 43, 44, 48, 47, 46, 45, 44, 39, 36, 36, 32, 29, 26, 25, 23, 21, 21, 20, 19, 18, 18, 17, 16, 16, 16, 18, 22, 24, 26, 30, 30, 30, 28, 31, 30, 22, 23, 25, 27, 29, 30, 29, 29, 32, 31, 32, 35, 33, 31, 31, 33, 32, 30, 31, 35, 35, 33, 31, 30, 29, 28, 28, 28, 21, 20, 20, 20, 20, 20, 21, 22, 22, 22, 23, 24, 24, 25, 24, 25, 24, 24, 23, 24, 23, 23, 25, 23, 24, 25, 24, 23, 24, 22, 25, 27, 29, 28, 31, 39, 50, 57, 53, 56, 49, 48, 45, 45, 46, 47, 46, 44, 42, 42, 41, 37, 36, 34, 33, 36, 40, 46, 49, 55, 56, 57, 62, 64, 58, 56, 59, 57, 60, 65, 60, 55, 48, 30, 29, 30, 28, 29, 31, 35, 29, 29, 31, 37, 44, 43, 44, 45, 45, 43, 39, 34, 32, 33, 33, 35, 34, 36, 38, 40, 38, 43, 46, 46, 41, 42, 42, 42, 42, 42, 41, 43, 45, 46, 47, 46, 44, 42, 42, 48, 46, 48, 47, 49, 50, 51, 50, 51, 58, 58, 60, 64, 57, 58, 65, 71, 74, 73, 66, 63, 66, 54, 48, 46, 48, 53, 58, 59, 58, 49, 40, 38, 37, 39, 40, 40, 45, 48, 48, 47, 47, 46, 44, 42, 42, 43, 41, 40, 39, 41, 41, 37, 39, 36, 34, 34, 34, 34, 34, 36, 35, 30, 29, 31, 34, 37, 41, 42, 45, 46, 48, 50, 50, 48, 43, 41, 42, 40, 37, 34, 34, 31, 30, 30, 29, 28, 27, 27, 26, 25, 24, 25, 24, 25, 24, 25, 26, 28, 29, 28, 26, 26, 26, 26, 26, 27, 27, 26, 29, 30, 28, 28, 26, 23, 23, 23, 21, 21, 21, 21, 22, 25, 24, 24, 24, 26, 27, 27, 28, 28, 28, 29, 30, 30, 29, 29, 28, 27, 26, 25, 24, 24, 24, 23, 23, 26, 26, 26, 26, 27, 28, 30, 31, 32, 32, 31, 32, 34, 36, 36, 34, 30, 27, 25, 25, 23, 21, 22, 24, 23, 22, 22, 25, 25, 28, 30, 29, 29, 30, 29, 28, 35, 37, 37, 37, 30, 32, 30, 29, 27, 25, 23, 23, 24, 24, 24, 24, 25, 25, 27, 31, 32, 33, 32, 34, 46, 50, 41, 35, 34, 35, 38, 36, 34, 33, 33, 35, 36, 30, 29, 30, 31, 31, 34, 36, 37, 40, 42, 46, 51, 56, 56, 40, 38, 35, 35, 36, 36, 36, 38, 40, 43, 40, 36, 36, 36, 36, 34, 35, 36, 36, 36, 35, 37, 37, 38, 37, 39, 41, 44, 48, 52, 58, 63, 65, 68, 71, 71, 65, 60, 58, 58, 59, 57, 57, 59, 60, 62, 62, 62, 61, 64, 64, 63, 65, 67, 70, 72, 73, 70, 81, 82, 84, 85, 88, 91, 93, 89, 80, 74, 70, 74, 75, 76, 76, 77, 79, 79, 82, 82, 86, 89, 87, 86, 93, 95, 94, 90, 87, 82, 83, 85, 94, 103, 101, 101, 96, 85, 86, 80, 66, 52, 48]

calPerformance(y_true,y_pred)

你可能感兴趣的:(回归模型的score得分为负)