I'm writing custom metric function and here's the steps I implemented:
- I have a list of floats in
predsand list ofint0-1values intarget - I round
preds - I need to make
groupbyonpreds - Count mean
targetvalues for those groupedbypreds - Count
MSEbetween groupedbypredsandtarget
That's how df looks like before groupby
rounded = [np.round(x, 2) for x in preds]
df = pd.DataFrame({'target': target, 'preds': rounded})
df = df.groupby('preds')['target'].mean().to_frame().reset_index()
mse = mean_squared_error(df['target'], df['preds'])
And that's how after groupby and mean() (as I can't properly display groupby)
Basicaly, I don't know how to groupby on two python lists.
I did groupby on one list like that
gr_list = [list(j) for i, j in groupby(rounded)]
But I have no clue how to groupby second list, based on gr_list groupping


Not the cleanest code, but I managed to do it like that: