Classification Workflows
Classification Threshold
Turn Scores Into Labels
A classifier often turns probabilities into labels by comparing each score with a cutoff.
Program
Play the script to change the cutoff and see how many records are classified as yes.
classification_threshold.R
Replay: real traced execution (multi-file project)
cutoff <- 0.6
prob <- c(0.20, 0.65, 0.80, 0.55)
predicted <- ifelse(prob >= cutoff, "yes", "no")
yes_count <- sum(predicted == "yes")
label <- paste("yes", yes_count, sep = ":")
cat(label, "\n", sep = "")
cutoff <- 0.5
prob <- c(0.20, 0.65, 0.80, 0.55)
predicted <- ifelse(prob >= cutoff, "yes", "no")
yes_count <- sum(predicted == "yes")
label <- paste("yes", yes_count, sep = ":")
cat(label, "\n", sep = "")
cutoff <- 0.7
prob <- c(0.20, 0.65, 0.80, 0.55)
predicted <- ifelse(prob >= cutoff, "yes", "no")
yes_count <- sum(predicted == "yes")
label <- paste("yes", yes_count, sep = ":")
cat(label, "\n", sep = "")
cutoff ← 0.6
1cutoff <- 0.62prob <- c(0.20, 0.65, 0.80, 0.55)values this step0.6cutoffprob ← 0.20, 0.65, 0.80, 0.55
1cutoff <- 0.62prob <- c(0.20, 0.65, 0.80, 0.55)3predicted <- ifelse(prob >= cutoff, "yes", "no")values this step0.20, 0.65, 0.80, 0.55probpredicted ← no, yes, yes, no
2prob <- c(0.20, 0.65, 0.80, 0.55)3predicted <- ifelse(prob >= cutoff, "yes", "no")4yes_count <- sum(predicted == "yes")values this stepno, yes, yes, nopredicted4 scoresprob0.6cutoffyes_count ← 2
3predicted <- ifelse(prob >= cutoff, "yes", "no")4yes_count <- sum(predicted == "yes")5label <- paste("yes", yes_count, sep = ":")values this step2yes_countno, yes, yes, nopredictedlabel ← yes:2
4yes_count <- sum(predicted == "yes")5label <- paste("yes", yes_count, sep = ":")6cat(label, "\n", sep = "")values this stepyes:2label2yes_countcat(label, " ", sep = "")
5label <- paste("yes", yes_count, sep = ":")6cat(label, "\n", sep = "")outputyes:2values this stepyes:2label
cutoff ← 0.5
1cutoff <- 0.52prob <- c(0.20, 0.65, 0.80, 0.55)values this step0.5cutoffprob ← 0.20, 0.65, 0.80, 0.55
1cutoff <- 0.52prob <- c(0.20, 0.65, 0.80, 0.55)3predicted <- ifelse(prob >= cutoff, "yes", "no")values this step0.20, 0.65, 0.80, 0.55probpredicted ← no, yes, yes, yes
2prob <- c(0.20, 0.65, 0.80, 0.55)3predicted <- ifelse(prob >= cutoff, "yes", "no")4yes_count <- sum(predicted == "yes")values this stepno, yes, yes, yespredicted4 scoresprob0.5cutoffyes_count ← 3
3predicted <- ifelse(prob >= cutoff, "yes", "no")4yes_count <- sum(predicted == "yes")5label <- paste("yes", yes_count, sep = ":")values this step3yes_countno, yes, yes, yespredictedlabel ← yes:3
4yes_count <- sum(predicted == "yes")5label <- paste("yes", yes_count, sep = ":")6cat(label, "\n", sep = "")values this stepyes:3label3yes_countcat(label, " ", sep = "")
5label <- paste("yes", yes_count, sep = ":")6cat(label, "\n", sep = "")outputyes:3values this stepyes:3label
cutoff ← 0.7
1cutoff <- 0.72prob <- c(0.20, 0.65, 0.80, 0.55)values this step0.7cutoffprob ← 0.20, 0.65, 0.80, 0.55
1cutoff <- 0.72prob <- c(0.20, 0.65, 0.80, 0.55)3predicted <- ifelse(prob >= cutoff, "yes", "no")values this step0.20, 0.65, 0.80, 0.55probpredicted ← no, no, yes, no
2prob <- c(0.20, 0.65, 0.80, 0.55)3predicted <- ifelse(prob >= cutoff, "yes", "no")4yes_count <- sum(predicted == "yes")values this stepno, no, yes, nopredicted4 scoresprob0.7cutoffyes_count ← 1
3predicted <- ifelse(prob >= cutoff, "yes", "no")4yes_count <- sum(predicted == "yes")5label <- paste("yes", yes_count, sep = ":")values this step1yes_countno, no, yes, nopredictedlabel ← yes:1
4yes_count <- sum(predicted == "yes")5label <- paste("yes", yes_count, sep = ":")6cat(label, "\n", sep = "")values this stepyes:1label1yes_countcat(label, " ", sep = "")
5label <- paste("yes", yes_count, sep = ":")6cat(label, "\n", sep = "")outputyes:1values this stepyes:1label
probability
Scores near 1 are stronger evidence for the positive class.
threshold
`prob >= cutoff` creates one decision per score.
label count
Counting labels gives a quick summary of classifier output.