一、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
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
评论(0)