When you use max(perf@y.values[[1]])
, it is computing the maximum accuracy across any possible cutoff for predicting a positive.
In your case, the optimal threshold is p=0.2
, at which you make 2 mistakes (on the observations with predicted probabilities 0.38 and 0.78), yielding a maximum accuracy of 0.8.
You can access the cutoffs for your perf object using perf@x.values[[1]]
.