yoklainterview sim

ML Engineer Cml Distance Clustering Dimreduction Interview Questions

75 verified ML Engineer Cml Distance Clustering Dimreduction interview questions — solve with answers, learn from explanations, test yourself in a real simulation.

Try the real simulation →

Sample questions

Cml Distance Clustering DimreductionDifficulty 1
In scikit-learn, what does KNeighborsClassifier.fit(X, y) actually do?
  • aIt stores the training set inside a neighbour-search index and estimates no parameters
  • bIt estimates one weight per feature by minimising squared error over the training rows
  • cIt computes one centroid per class label and keeps only those centroids for prediction
  • dIt builds threshold rules by recursively splitting the feature space into pure regions
Explanation:k-nearest-neighbours is a lazy learner: fitting only memorises the training rows, optionally organising them into a KD-tree or ball-tree for faster lookup. No coefficients, centroids or split rules are derived, which is why training is nearly free while every prediction pays the neighbour-search cost.
Cml Distance Clustering DimreductionDifficulty 2
As n_neighbors grows in a k-nearest-neighbours classifier, how does the decision boundary behave?
  • aIt becomes exactly linear as soon as k passes the number of input features
  • bIt grows more jagged, because a larger committee of neighbours votes on each query
  • cIt grows smoother, which lowers variance and raises bias
  • dIts shape stays the same and only the per-query prediction latency grows with k
Explanation:Each prediction averages the votes of k neighbours, so a larger k averages over a wider region and the boundary loses its fine detail. That is the classic bias-variance trade of the method: k=1 tracks every individual label, and very large k drifts toward predicting the majority class everywhere.
Cml Distance Clustering DimreductionDifficulty 2
A KNeighborsClassifier(n_neighbors=5) on the wine dataset scores 0.69 unscaled and about 0.95 with either StandardScaler or MinMaxScaler in front. Yet under the two scalers 125 of the 178 rows end up with a different set of five neighbours. Why do the two disagree?
  • aMinMaxScaler leaves the columns correlated while StandardScaler removes that correlation first
  • bMapping into [0, 1] discards the sign of each value, which the squared difference relies on
  • cThe two place the origin differently, and a shifted origin changes which rows come out closest
  • dOne divides a column by its standard deviation and the other by its range, so the weights differ
Explanation:Both transforms remove the raw-unit problem, which is why the accuracy lands in the same place either way, but there is more than one way to make columns comparable. A column carrying one distant extreme value has a wide range and only a modest standard deviation, so min-max squeezes it far harder than standardising does. Each column therefore enters the squared sum with a different weight under the two, and the resulting neighbour lists overlap on average in 4.06 of their 5 places.
Cml Distance Clustering DimreductionDifficulty 2
A team switches a kNN classifier from weights='uniform' to weights='distance', and predictions change mostly for query points sitting near a class boundary. What did the switch change?
  • aNeighbours farther away than the mean neighbour distance are now dropped from the vote entirely
  • bEach of the k neighbours now votes with weight proportional to 1/d
  • ck is now recomputed for each query point from the local density of the surrounding training rows
  • dThe metric changed from Minkowski to a weighted distance that is learned during the fit
Explanation:With uniform weights all k neighbours count equally, so a query just outside a dense region can be outvoted by slightly farther points of the other class. Inverse-distance weighting keeps the same k neighbours but lets the closest ones dominate, which is exactly where boundary points shift.
Cml Distance Clustering DimreductionDifficulty 2
What does this snippet print (scikit-learn 1.6)?

from sklearn.metrics import pairwise_distances
a = [[0, 0]]
b = [[3, 4]]
print(pairwise_distances(a, b, metric="minkowski", p=1)[0, 0],
      pairwise_distances(a, b, metric="minkowski", p=2)[0, 0])
  • a12.0 5.0
  • b5.0 7.0
  • c7.0 7.0
  • d7.0 5.0
Explanation:Minkowski with p=1 is the Manhattan distance, |3| + |4| = 7. With p=2 it is the Euclidean distance, sqrt(9 + 16) = 5. The exponent p is what turns one metric into the other, and it is the default p=2 that makes kNN Euclidean out of the box.
Cml Distance Clustering DimreductionDifficulty 1
Which quantity does KMeans minimise, and what does its inertia_ attribute therefore report?
  • aThe mean silhouette coefficient computed over all of the assigned samples
  • bThe sum over all samples of the squared distance to the assigned centroid
  • cThe log-likelihood of the data under one Gaussian component per cluster
  • dThe sum of the pairwise distances between every pair of fitted centroids
Explanation:The k-means objective is the within-cluster sum of squares, and inertia_ holds exactly that value after the fit. Because the criterion is a sum of squared Euclidean distances to a mean, the whole algorithm inherits a preference for compact, roughly spherical groups.

Test yourself against the 1050-question ML Engineer bank.

Start interview