python计算均方根误差(python如何实现均方误差和均方根误差?)
导读:一、python实现...
一 、python实现均方误差
均方误差是各数据偏离真实值的距离平方和的平均数 ,也即误差平方和的平均数 。
用法:一般被用在机器学习的预测值与真实值之间的距离 。均方误差对应的是最小二乘法。
#-*-coding:utf-8-*- importmath defget_mse(records_real,records_predict): """ 均方误差 """ iflen(records_real)==len(records_predict): returnsum([(x-y)**2forx,yinzip(records_real,records_predict)])/len(records_real) else: returnNone二 、python实现均方根误差
#-*-coding:utf-8-*- importmath defget_rmse(records_real,records_predict): """ 均方根误差 """ mse=get_mse(records_real,records_predict) ifmse: returnmath.sqrt(mse) else: returnNone创心域SEO版权声明:以上内容作者已申请原创保护,未经允许不得转载,侵权必究!授权事宜、对本内容有异议或投诉,敬请联系网站管理员,我们将尽快回复您,谢谢合作!