One-vs-Rest and One-vs-One — ML Technical Interview Questions & Answers

Extending binary classifiers to multiple classes.

One-vs-Rest and One-vs-One

  • Simple meaning: One-vs-rest (OvR): train one binary model per class (“A vs not A”, “B vs not B”). One-vs-one (OvO): a model for every pair of classes, then vote.
  • Picture: Grades A/B/C. OvR = three models. OvO = A vs B, A vs C, B vs C (three pairs too for three classes; for many classes OvO grows fast).
  • sklearn often does OvR for linear models. Trees and softmax nets handle many classes in one model.
  • Trap: forgetting that pair models can disagree. Trap: using OvO on 100 classes without saying the cost.

Technical Interview Tip: Many labels: OvR or OvO, or a model that is native multiclass.

Code Examples for One-vs-Rest and One-vs-One

One-vs-Rest and One-vs-One — working example

# ROC idea: vary threshold on scores
y_true = [0, 0, 1, 1]
scores = [0.1, 0.4, 0.35, 0.8]

def tpr_fpr(threshold):
    pred = [1 if s >= threshold else 0 for s in scores]
    tp = sum(t == 1 and p == 1 for t, p in zip(y_true, pred))
    fp = sum(t == 0 and p == 1 for t, p in zip(y_true, pred))
    fn = sum(t == 1 and p == 0 for t, p in zip(y_true, pred))
    tn = sum(t == 0 and p == 0 for t, p in zip(y_true, pred))
    tpr = tp / (tp + fn)
    fpr = fp / (fp + tn)
    return tpr, fpr

for thr in (0.3, 0.5, 0.75):
    print(thr, tpr_fpr(thr))
# Boosting: train trees sequentially on residuals / hard examples

One-vs-Rest and One-vs-One — rOC plots TPR vs FPR across thresholds; AUC summarizes ranking quality. Boosting builds strong learners from weak ones.

How to Explain One-vs-Rest and One-vs-One to an Interviewer

One-vs-rest?

One binary model per class vs all others

One-vs-one?

A model for each pair of classes