本文共 948 字,大约阅读时间需要 3 分钟。
对于分类问题,评价测度是准确率,但这种方法不适用于回归问题。我们使用针对连续数值的评价测度(evaluation metrics)。
下面介绍三种常用的针对回归问题的评价测度
In [21]:
# define true and predicted response valuestrue = [100, 50, 30, 20]pred = [90, 50, 50, 30]
(1)平均绝对误差(Mean Absolute Error, MAE)
(2)均方误差(Mean Squared Error, MSE)
(3)均方根误差(Root Mean Squared Error, RMSE)
In [24]:
from sklearn import metricsimport numpy as np# calculate MAE by handprint "MAE by hand:",(10 + 0 + 20 + 10)/4.# calculate MAE using scikit-learnprint "MAE:",metrics.mean_absolute_error(true, pred)# calculate MSE by handprint "MSE by hand:",(10**2 + 0**2 + 20**2 + 10**2)/4.# calculate MSE using scikit-learnprint "MSE:",metrics.mean_squared_error(true, pred)# calculate RMSE by handprint "RMSE by hand:",np.sqrt((10**2 + 0**2 + 20**2 + 10**2)/4.)# calculate RMSE using scikit-learnprint "RMSE:",np.sqrt(metrics.mean_squared_error(true, pred))
MAE by hand: 10.0MAE: 10.0MSE by hand: 150.0MSE: 150.0RMSE by hand: 12.2474487139RMSE: 12.247448713
转载地址:http://flgad.baihongyu.com/