Lesson deck

k-NN, k-means, PCA, SVM and naive Bayes: the classical toolkit flashcards

Reviewing needs JavaScript. You can read every card in the list below.

Loading your cards...

Back to the lesson13 cards in this deck

Read all 13 cards as a list
  1. Front
    How does k-NN classify a point, and what does choosing k trade off?
    Back
    It stores the training data, finds the k closest rows and takes a majority vote. Small k follows noise (high variance; 1-NN scores 100% on its own training set, barring duplicate rows with different labels); large k blurs the boundary (high bias). Choose k on validation data.
  2. Front
    What is the curse of dimensionality for distance-based methods?
    Back
    As dimension grows, the nearest point's distance approaches the farthest point's (Beyer et al.: seen from about 10 to 15 dimensions in their experiments). In the lesson's random-data run, nearest/farthest was 0.04 at d = 2 and 0.91 at d = 1000. Neighbours then carry little local information, unless the data has low-dimensional structure.
  3. Front
    Why must columns be scaled before k-NN, and what happens if you do not?
    Back
    Euclidean distance adds squared differences, so a column in large units decides the neighbours. In the lesson, one noise column at 100 times the scale took 5-NN from 0.950 to 0.530, below the 0.607 majority baseline. Fit the scaler on training data only.
  4. Front
    State the two steps of Lloyd's k-means loop and what it minimises.
    Back
    Assign each row to its nearest centre; move each centre to the mean of its rows; repeat until assignments stop changing. It minimises the inertia J, the sum of squared distances to the assigned centre. J never rises, so the loop converges, but only to a local optimum.
  5. Front
    What does k-means++ change, and what does it not guarantee?
    Back
    After a random first centre, each next centre is drawn with probability proportional to its squared distance from the nearest chosen centre. It is O(log k)-competitive in expectation. In the lesson it raised good runs from 72% to 87% but its worst run was still 2.4 times the best J, so also restart and keep the lowest J.
  6. Front
    How do you choose k in k-means, and why not just minimise inertia?
    Back
    Inertia falls as k grows and is zero at k = n. Look for the elbow where the drop slows, and the silhouette s = (b - a) / max(a, b) (between -1 and 1; higher is better separated), then check stability across restarts and usefulness for the decision. There is no rule that always works.
  7. Front
    Name three ways k-means fails and the fix for each.
    Back
    Non-convex shapes such as rings (purity 0.52 in the lesson): use DBSCAN or single linkage. Unscaled columns: standardise. Outliers (one point at distance 100 took a whole cluster): remove or cap them, or use a method that labels noise. In all three the objective, a sum of squared distances to a mean, is the cause.
  8. Front
    List the PCA steps and what the explained variance ratio is.
    Back
    Centre the columns, form the covariance matrix (divide by n - 1), take its eigenvectors sorted by eigenvalue, project onto the top k. Each component's explained variance is its eigenvalue; the ratio is that eigenvalue over the sum of all eigenvalues. Example: covariance rows (2, 1) and (1, 2) has eigenvalues 3 and 1, ratios 3/4 and 1/4.
  9. Front
    When does PCA mislead?
    Back
    Units: an unscaled big-unit column takes PC1 (0.999998 of the variance in the lesson). Quiet signal: PCA never sees labels, so a class signal in a low-variance direction is dropped (PC1 only 0.508, PC2 only 1.000). Curved structure: PCA is linear. Readability: components mix all columns.
  10. Front
    State the linear SVM objective and what C does.
    Back
    Minimise 1/2 ||w||^2 + C times the sum of hinge losses max(0, 1 - y f(x)). The first term widens the margin (width 2/||w||); the hinge charges points inside it. Low C gives a wide, smooth margin; high C a narrow one that fits training points. Points beyond margin 1 have zero loss. SVMs are not scale invariant.
  11. Front
    What is the kernel trick, in one example?
    Back
    A kernel computes the inner product of lifted features without building them. For two columns, (x . z)^2 = x1^2 z1^2 + 2 x1 x2 z1 z2 + x2^2 z2^2, the dot product of the lifted vectors (x1^2, sqrt2 x1 x2, x2^2). It lets a linear SVM separate a disc (0.604 linear, 0.978 with x1^2 + x2^2 added).
  12. Front
    State the naive Bayes assumption and why it still classifies well.
    Back
    Features are independent given the class, so P(y | x) is proportional to P(y) times the product of P(x_j | y). Classification needs only which class scores higher. Duplicating every feature 3 times left accuracy at 0.800 but raised confidence from 0.810 to 0.928: decisions survive, probabilities do not. One dominant duplicate can break it (0.650).
  13. Front
    What do a Gaussian mixture, Isolation Forest and t-SNE add to k-means and PCA, and what is the catch of each?
    Back
    GMM fits Gaussians with their own covariance by EM (soft assignments, local optimum, BIC for the number of components). Isolation Forest scores points by how few random splits isolate them (shorter path means more anomalous). t-SNE draws 2-3 D maps only: seed-dependent, no transform for new rows, so its islands are not features.