Skip to content

Perfect Brownies Solution


Precision = 0.67, Recall = 0.5

df['pred_class'] = df.yhat >= 0.5

# Calculate True Positives, False Positives, False Negatives
TP = ((df.pred_class == True) & (df.y == True)).sum()
FP = ((df.pred_class == True) & (df.y == False)).sum()
FN = ((df.pred_class == False) & (df.y == True)).sum()

# Calculate precision, recall
precision = TP/(TP + FP)  # 0.67
recall = TP/(TP + FN)     # 0.50
# Insert pred_class column
df$pred_class <- df$yhat >= 0.5

# Calculate True Positives, False Positives, False Negatives
TP <- sum(df$pred_class == T & df$y == T)
FP <- sum(df$pred_class == T & df$y == F)
FN <- sum(df$pred_class == F & df$y == T)

# Calculate precision, recall
precision <- TP/(TP + FP)  # 0.67
recall <- TP/(TP + FN)     # 0.50