Fixing the auc_group Function: A Simple Modification to Resolve Error

The error occurs because the auc_group function is missing the required positional argument y. The function should take two arguments, the whole dataframe and the y values. To fix this issue, we need to modify the auc_group function to accept only one argument - the dataframe.

Here’s how you can do it:

def auc_group(df):
    y_hat = df.y_hat.values
    y = df.y.values
    return roc_auc_score(y_hat, y)

test.groupby(["Dataset", "Algo"]).apply(auc_group)

In this modified function, y_hat and y are extracted from the dataframe using the .values attribute. This is because pandas DataFrames don’t have built-in support for accessing column values without indexing.

This modification should now solve your problem.


Last modified on 2025-03-20