需要一個使用Pandas DataFrame計算RMSE的簡單示例。提供有功能,在循環真正的返回和預測值:Python Pandas:從數據幀計算RMSE的簡單示例
def fun (data):
...
return trueVal, predVal
for data in set:
fun(data)
然後一些代碼,使這些結果在下面的數據幀中x
是一個真正的價值和p
是一個預測值:
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
數據框?
2)如何使用df
數據框計算RMSE?
檢查:http://stackoverflow.com/questions/17197492/root-mean- python中的平方誤差 – MYGz
可能的重複[均方根誤差i ((df.p - df.x)** 2)。(https://stackoverflow.com/questions/17197492/root-mean-square-error-in-python) –