计算具有一定范围的数据帧行的MSE,RMSE直到数据框架结束
我有一个数据框架df
,它具有两个列true
和预测
,而数据框架有1000行。我想使用sklearn mean_squared_error(y_test,y_pred)
的函数来计算MSE和RMSE。但是,我想以一种模式来计算它们,以便将第一个MSE在true
和预测
列值的前20行中计算。然后,下一个MSE将从true
和预测
列上的21-40行值上。因此,我想从总共1000行中连续每20行计算一堆MSE和RMSE,并将它们安排在数据框架中。我无法找到循环条件。我在范围(0,len(df),20)中尝试了,但它不起作用。我该如何解决? 例如,数据帧是
>df
True Prediction
0 5 5
1 6 4
2 7 2
3 2 3
..
1000 1 3
输出将是这样的数据
MSE RMSE
0 1.5 2.5
1 1 0.5
2 1 1.2
...
50 2 3.7
框
I have a data frame df
which has two column True
and Prediction
while the data frame has 1000 rows. I want to calculate MSE and RMSE using function from sklearn mean_squared_error(y_test, y_pred)
. But I want to keep calculating them in a pattern such that, the 1st MSE will be calculated on the first 20 rows of True
and prediction
column values. Then next MSE will be on 21-40 row values from the True
and Prediction
column. Thus I want to calculate a bunch of MSE and RMSE taking every 20 rows consecutively from the total 1000 rows and arranging them in a data frame. I am not being able to find loop condition for that. I tried for i in range(0,len(df),20)
but its not working. How could I solve this?
For example, the data frame is
>df
True Prediction
0 5 5
1 6 4
2 7 2
3 2 3
..
1000 1 3
The output will be a data frame like this
MSE RMSE
0 1.5 2.5
1 1 0.5
2 1 1.2
...
50 2 3.7
As each MSE and RMSE will be based on 20 rows of True and Prediction value, there will be only 50 rows in the new data frame of MSE and RMSE
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这应该适用于 MSE:
请参阅此处的实时实施
This should work for MSE:
See live implementation here