Python Pandas:从数据帧计算RMSE的简单示例 [英] Python Pandas: Simple example of calculating RMSE from data frame

查看:1099
本文介绍了Python Pandas:从数据帧计算RMSE的简单示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

需要一个使用Pandas DataFrame计算RMSE的简单示例.提供可以按周期返回真实值和预测值的函数:

Need a simple example of calculating RMSE with Pandas DataFrame. Providing there is function that returns in cycle true and predicted value:

def fun (data):
   ...
   return trueVal, predVal

for data in set:
   fun(data)

然后一些代码将这些结果放入以下数据帧中,其中x是真实值,而p是预测值:

And then some code puts these results in the following data frame where x is a real value and p is a predicted value:

In [20]: d
Out[20]: {'p': [1, 10, 4, 5, 5], 'x': [1, 2, 3, 4, 5]}

In [21]: df = pd.DataFrame(d)

In [22]: df
Out[22]: 
    p  x
0   1  1
1  10  2
2   4  3
3   5  4
4   5  5

问题:

1)如何将fun函数的结果放入df数据框中?

1) How to put results from fun function in df data frame?

2)如何使用df数据帧计算RMSE?

2) How to calculate RMSE using df data frame?

推荐答案

问题1
这取决于数据的格式.我希望您已经有了自己的真实值,因此该功能只是传递.

Question 1
This depends on the format that data is in. And I'd expect you already have your true values, so this function is just a pass through.

问题2

Question 2

使用pandas
((df.p - df.x) ** 2).mean() ** .5

使用numpy
(np.diff(df.values) ** 2).mean() ** .5

这篇关于Python Pandas:从数据帧计算RMSE的简单示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆