package Jenkins 人脸识别 database Validator Plupload 后台界面模板 sql视频教程 jquery对象 js空格符 leach算法 java常用的包 windows杀进程命令 python在线教程 python关键字 python环境变量 python平台 python读取mysql数据 python命令大全 javasubstring 搭建java开发环境 java8函数式接口 java中continue java线程死锁 java集合类型 java数据类型转换 linux启动 linux装机 linux内核编程 ad19 电视免费软件 免费脚本 js小数点保留2位 bz2 猫眼电影票 winhex中文版下载 0000008e opencv是什么 ajax获取数据 ps怎么复制粘贴
当前位置: 首页 > 学习教程  > 编程语言

[模型评测]回归模型评测的4种方式

2020/7/24 10:19:37 文章标签:

1.方式
MAE, MSE, RMSE, R-Squared

The MSE, MAE, RMSE, and R-Squared are mainly used metrics to evaluate the prediction error rates 
and model performance in regression analysis.
MAE (Mean absolute error) represents the difference between the original and predicted values 
    extracted by averaged the absolute difference over the data set.
MSE (Mean Squared Error) represents the difference between the original and predicted values 
    extracted by squared the average difference over the data set.
RMSE (Root Mean Squared Error) is the error rate by the square root of MSE.
R-squared (Coefficient of determination) represents the coefficient of how well the values fit compared 
to the original values. The value from 0 to 1 interpreted as percentages. The higher the value is, the better the model is.

2.准备数据
import numpy as np 
import sklearn.metrics as metrics
import matplotlib.pyplot as plt
y = np.array([-3, -1, -2, 1, -1, 1, 2, 1, 3, 4, 3, 5])
yhat = np.array([-2, 1, -1, 0, -1, 1, 2, 2, 3, 3, 3, 5])
x = list(range(len(y)))

plt.scatter(x, y, color="blue", label="original")
plt.plot(x, yhat, color="red", label="predicted")
plt.legend()
plt.show() 
 
3.使用公式评测
d = y - yhat
mse_f = np.mean(d**2)
mae_f = np.mean(abs(d))
rmse_f = np.sqrt(mse_f)
r2_f = 1-(sum(d**2)/sum((y-np.mean(y))**2))

print("Results by manual calculation:")
print("MAE:",mae_f)
print("MSE:", mse_f)
print("RMSE:", rmse_f)
print("R-Squared:", r2_f)
 
4.使用sklearn.metrics评测
mae = metrics.mean_absolute_error(y, yhat)
mse = metrics.mean_squared_error(y, yhat)
rmse = np.sqrt(mse) # or mse**(0.5)  
r2 = metrics.r2_score(y,yhat)

print("Results of sklearn.metrics:")
print("MAE:",mae)
print("MSE:", mse)
print("RMSE:", rmse)
print("R-Squared:", r2)
 


本文链接: http://www.dtmao.cc/news_show_50230.shtml

附件下载

相关教程

    暂无相关的数据...

共有条评论 网友评论

验证码: 看不清楚?