Vectors and norms interview questions
14 questions interviewers ask on vectors, from first principles to the follow-ups. The first 3 model answers are free to read; Pro opens the rest.
- What is a vector in machine learning, and what is its dimension?
An ordered list of numbers, usually one row of features. Its dimension is the number of components: Grace's shop-day
(981, 1, −1.2, 33)is inℝ⁴. Order matters, because each position is a feature. - What is the difference between shapes
(d,),(1, d)and(d, 1)in NumPy?(d,)is a 1-D array with one axis, neither a row nor a column;(1, d)is a row matrix and(d, 1)a column matrix..Tleaves a 1-D array unchanged, so usereshapewhen the orientation matters. - Name three norms and when you would use each.
L2,
√(Σ vᵢ²), the straight-line length and the default; L1,Σ |vᵢ|, the grid length, less affected by one large component and the basis of the lasso penalty; L∞,max |vᵢ|, the largest single deviation. For(3, −4)they give5,7and4. - Why does lasso set weights to exactly zero and ridge does not?
- Why must features be scaled before k-nearest neighbours?
- What does the dot product tell you geometrically?
- When would you use cosine similarity instead of Euclidean distance?
- What is a projection, and where is it used?
- What does
w · x + b = 0describe, and what arewandb? - Is a larger score
w · x + ba larger distance from the boundary? - A linear classifier gets 14 of 16 on a small dataset. Could another line do better?
- What is the curse of dimensionality?
- Does having 64 features mean nearest neighbours will fail?
- Why do decision trees struggle with diagonal boundaries?