Home > Mobile >  How to apply accuracy_score function to two columns in group by
How to apply accuracy_score function to two columns in group by

Time:02-15

I have the following data frame:

wn  Ground_truth   Prediction
A        1              1
A        1              1
A        1              0
A        1              1
B        0              1
B        1              1
B        0              0

for each group ( A , B) i would like to calculate the accuracy_score(Ground_truth, Prediction)

CodePudding user response:

Specifically for accuracy you can actually do something simpler:

df.assign(x=df['Ground_truth']==df['Prediction']).groupby('wn').mean()

CodePudding user response:

you can use the accuracy_score function from sklearn. You can check their document from here

from sklearn.metrics import accuracy_score

ground_truth = df["Ground_truth"].values
predictions = df["Prediction"].values

accuracy = accuracy_score(ground_truth, predictions)
  • Related