'Python to compute MSE for every row
I am trying to compute the MSE for every row in my dataframe,
Below is my code-
import pandas as pd
s={'AValues':[1,1,2,2],'month':[2016,2017,2018,2019],'fvalues':[55,66,77,88],'Fruits':['Apple','Mango','Orange','Banana']}
p=pd.DataFrame(data=s)
mse_df=pd.pivot_table(p,index='Fruits',columns='month',values=['AValues','fvalues'])
mse_df=mse_df.fillna(0)
This is how the dataframe output of above code looks like-

I wanted to calculate here mse for Apples, Banana, Mango and Orange i.e row by row. (AValues- actual values , fvalues- forecasted values)
I am trying the below code-
from sklearn.metrics import mean_squared_error
mean_squared_error(mse_df['AValues'],mse_df['fvalues'])
But, it's giving me the total mse and not individual or row by row.
Can you please help me on how the mse can be found out?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
