Skip to content
Tech Interview Prep
Technical interview guide

Supervised vs. Unsupervised Learning

Learning from labeled examples versus finding structure in unlabeled data, and where semi-supervised and reinforcement learning fit.

Minutes to read
3
Practice MCQs
25
Interview Q&A
25
Edition
v5
Editorial status
Reviewed

Scope: scikit-learn stable documentation and Google Machine Learning Crash Course accessed 2026-08-30..

Overview

Curated: · Written: · Reviewed:

Supervised vs. Unsupervised Learning

In one line

Supervised learning maps inputs to a target you can observe after the fact. Unsupervised learning finds structure (clusters, components, embeddings, densities, anomalies) with no target. Reach for supervised when the decision has a trustworthy label available at prediction time, and for unsupervised when you need structure to segment, prioritize review, or choose what to label.

Key definitions

  • Target: the outcome, with its prediction time, label window and eligible population. A convenient column is not a target until those are fixed.
  • Leakage: a feature carries information that does not exist at prediction time, such as a refund field used to predict dissatisfaction at order placement.
  • Pseudo-label: a model's own prediction written back as a training label.
  • Inertia: the within-cluster sum of squared distances that k-means minimizes. It falls as k rises, so it cannot choose k alone.
  • Silhouette: an internal cohesion-versus-separation score. It measures shape, not business value.
  • PU learning: positives are labeled and negatives are a mix of unlabeled cases.

Formulas and complexity

J=∑j=1k∑x∈Cj∥x−μj∥2J=\sum_{j=1}^{k}\sum_{x\in C_j}\lVert x-\mu_j\rVert^2

PCA takes the eigenvectors of the centered covariance matrix, ordered by eigenvalue. Worked check: for covariance [[5, 2], [2, 2]] the eigenvalues are 6 and 1, so the first principal component is (2, 1)/√5, the unit eigenvector for 6.

How it works

The first decision is whether a label exists at prediction time and is trustworthy. If yes, fit inputs to that target and evaluate on a split that matches deployment. If no, fit a representation or structure and validate it with stability checks, exemplar review and, where available, outcomes that were not used in fitting. Every learned transform (imputation, scaling, PCA, clustering, pseudo-labels) is fit inside the training portion of each fold.

yes no Raw data and decision Trustworthy label at prediction time? Supervised: fit inputs to target Unsupervised: fit structure Deployment-like held-out evaluation Stability, exemplars, outcome check Threshold or action chosen from costs

When to use and when not to

SituationSupervisedUnsupervised
Labeled outcome, clear decisionPreferredUse only as a supplement
Labels delayed, biased or missingRisky until auditedUseful for structure and review queues
Rare events with known confirmed casesRanks known patternsFinds novel ones, but contamination can mislead it
Segmentation with no action definedNot applicableAcceptable if validated downstream
Limited labels, unlabeled pool largeSemi-supervised or active labelingRepresentation first, then labels

Traps interviewers probe

  1. Fitting transforms before the split. Scaler, PCA and cluster models fit on all rows leak validation distribution. Fix: put every fit inside the training fold and re-run CV. A drop from 0.93 to 0.70 under this fix is evidence of leakage, not a bug.
  2. Random row splits on repeated entities or time. A patient or customer on both sides inflates AUC. Fix: split by entity, time or cohort, and keep a final untouched set from the future population.
  3. Post-outcome columns as target or feature. A refund issued after purchase cannot predict dissatisfaction at checkout. Fix: write down prediction time and drop anything recorded after it.
  4. Reading accuracy or a 0.5 threshold on rare events. A detector that flags almost nothing can score 99% accuracy. Fix: report precision, recall and PR-AUC against the prevalence baseline, then set the threshold from error costs, capacity and calibration.
  5. Treating a cluster ID as a segment. Label numbers are arbitrary and change with the seed. Fix: test stability across seeds and samples, then check whether outcome rates differ by cluster on held-out data.

Interview tips

Open by naming the target, its prediction time and its label source before naming any model family. Say what the decision is and what it costs to be wrong.

Expect these follow-ups: how you would split the data for repeat customers over time; how you prevent preprocessing leakage; how you choose k (stability and outcome spread, not inertia alone); whether self-training is safe (only with a human-labeled evaluation set, calibrated confidence and subgroup audits); how monitoring works when labels arrive late and only flagged cases get reviewed.

30-second outline:

  1. Target, prediction time and label source.
  2. Supervised or unsupervised, and why.
  3. Split that matches deployment, with fits kept inside folds.
  4. Metric matched to the decision, compared with a prevalence or rule baseline.
  5. How the output is validated and monitored after launch.

Feedback on this overview

Log in free to save your progress and keep bookmarks and notes for a quick revision before your interview.