Unsupervised learning: clustering, PCA and anomaly detection
- ML fundamentals
- Asked often
- About 2 h 30 min to learn
- 3 vetted resources
What this topic covers
Finding structure in data without labels. K-means splits points into k clusters by alternating assignments and centroid updates; it needs k chosen in advance, depends on its starting centroids and assumes compact clusters of similar size. Hierarchical clustering builds a tree of merges that you can cut at any level, and PCA finds the orthogonal directions of greatest variance for compression, visualisation or denoising. Anomaly detection flags points that fit the rest of the data poorly, with methods such as isolation forests or local outlier factor. Interviewers check that you can walk through k-means, choose k and a distance measure, explain why features must be scaled before k-means or PCA, and pick an anomaly detection approach when labels are scarce.
You’re ready when you can
What interviewers check, from the resources below.
- Explain the first principal component as the direction of greatest variance, and how loadings and scores relate
- Use the proportion of variance explained to choose how many components to keep
- Explain why variables are usually scaled before PCA and clustering
- Walk through the k-means algorithm and explain why it finds only a local optimum
- Describe how a dendrogram is built and how the choice of linkage changes the clusters
- Name the centroid, density, distribution and hierarchical families of clustering and a case for each
- Choose z-scores, log transforms or quantiles to prepare a feature before measuring similarity
- Judge cluster quality without labels using cardinality, magnitude and downstream performance
- Pick k with the elbow of the loss curve and list k-means’ main weaknesses with a remedy for each
- Distinguish outlier detection from novelty detection and say what training data each assumes
Unsupervised learning interview questions
Answer out loud, then open the points a strong answer covers. All Machine learning interview questions
Walk me through k-means. How do you choose k, and when does it fail?
- K-means alternates assigning each point to its nearest centroid and moving each centroid to the mean of its points, lowering within-cluster squared distance until it converges to a local optimum.
- Because the result depends on the starting centroids, run several initialisations or k-means++ and keep the best run; choose k from the elbow of the loss curve, silhouette scores or downstream usefulness.
- It assumes compact clusters of similar size and is pulled by outliers and unscaled features, so standardise first and consider DBSCAN, Gaussian mixtures or hierarchical clustering for other shapes.
What does PCA compute, and what should you watch out for when you use it?
- PCA finds orthogonal directions of maximum variance in centred data, the eigenvectors of the covariance matrix or right singular vectors of the data matrix, ordered by the variance each explains.
- Scale features first when their units differ, otherwise the leading components simply follow whichever feature has the largest numeric range rather than any shared structure in the data.
- Choose the number of components from the cumulative proportion of variance explained or a scree plot, and remember that high-variance directions are not necessarily the ones that predict the label.
What to study, in order
Each link opened and checked by hand; the date says when.
Start here
An Introduction to Statistical Learning (opens in a new tab)
statlearning.com · Gareth James, Daniela Witten, Trevor Hastie, Robert Tibshirani and Jonathan Taylor · 90 min · Free · checked 26 Oct 2026
- Why
- It explains PCA, k-means and hierarchical clustering with both the intuition and the maths interviewers expect, in one short chapter.
- What to read
- Download the free PDF of the Python edition (ISLP) from the home page. In chapter 12 read “12.1 The Challenge of Unsupervised Learning”, “12.2.1 What Are Principal Components?” to “12.2.4 More on PCA”, then “12.4.1 K-Means Clustering”, “12.4.2 Hierarchical Clustering” and “12.4.3 Practical Issues in Clustering”.
- What to skip
- “12.2.5 Other Uses for Principal Components”, “12.3 Missing Values and Matrix Completion”, and the lab unless you want to practise in code.
Free alternative
Introduction to clustering (opens in a new tab)
Google for Developers · Google for Developers · 60 min · Free · checked 26 Oct 2026
- Why
- It treats clustering as a practical workflow, from preparing data to judging the result, which is how interviewers pose it in product settings.
- What to read
- In the Overview unit read “What is clustering?”, “Clustering algorithms”, “Clustering workflow” and “Data preparation”; then the whole K-means clustering unit: “What is k-means clustering?”, “Manual similarity measure”, “Evaluating results” and “Advantages and disadvantages”.
- What to skip
- The Neural nets for clustering unit, unless you are also studying embedding-based similarity.
Go deeper
2.7. Novelty and Outlier Detection (opens in a new tab)
scikit-learn User Guide · scikit-learn developers · 30 min · Free · checked 26 Oct 2026
- Why
- Anomaly detection questions usually come with few or no labels, and this page sets out the main unsupervised detectors and when each one fits.
- What to read
- Read the introduction on outlier versus novelty detection, “2.7.1. Overview of outlier detection methods”, the opening of “2.7.2. Novelty Detection”, “2.7.3.2. Isolation Forest” and “2.7.3.3. Local Outlier Factor”.
- What to skip
- “2.7.2.1. Scaling up the One-Class SVM”, most of “2.7.3.1. Fitting an elliptic envelope”, “2.7.4. Novelty detection with Local Outlier Factor” and the plotting code.
Companies that test ML fundamentals most
Put Unsupervised learning in your plan
Tell us your interview date and hours a day; it lands on the right day, in the right order.