Skip to content

Perfect Brownies


You've developed a video monitoring system for ovens that alerts you when a batch of brownies is cooked to perfection. Through a delicious validation procedure, you've acquired the following predictions and truths.

import pandas as pd

df = pd.DataFrame({
    'yhat': [0.32, 0.65, 0.16, 0.1, 0.1, 0.78, 0.5, 0.03], 
    'y': [True, True, False, False, False, True, False, True]
})

print(df)
#    yhat      y
# 0  0.32   True
# 1  0.65   True
# 2  0.16  False
# 3  0.10  False
# 4  0.10  False
# 5  0.78   True
# 6  0.50  False
# 7  0.03   True
df <- data.frame(
  yhat = c(0.32, 0.65, 0.16, 0.1, 0.1, 0.78, 0.5, 0.03),
  y = c(TRUE, TRUE, FALSE, FALSE, FALSE, TRUE, FALSE, TRUE)
)

print(df)
# yhat     y
# 1 0.32  TRUE
# 2 0.65  TRUE
# 3 0.16 FALSE
# 4 0.10 FALSE
# 5 0.10 FALSE
# 6 0.78  TRUE
# 7 0.50 FALSE
# 8 0.03  TRUE

Calculate the precision and recall of your model using a prediction threshold of 0.5. That is, assume your model predicts True when yhat >= 0.5.


See the solution