What is the Euclidean distance between two points?
Euclidean distance is the straight-line distance between two points in space. It is calculated as the square root of the sum of squared differences between corresponding coordinates.
Click to reveal answer
beginner
How does the Cosine distance measure similarity between two vectors?
Cosine distance measures the angle between two vectors. It calculates 1 minus the cosine of the angle, focusing on direction rather than magnitude.
Click to reveal answer
beginner
What is the Manhattan distance and when is it useful?
Manhattan distance is the sum of absolute differences between coordinates of two points. It is useful in grid-like path problems, like city blocks.
Click to reveal answer
intermediate
How to calculate Euclidean distance using scipy?
Use scipy.spatial.distance.euclidean(point1, point2) to get the Euclidean distance between two points.
Click to reveal answer
intermediate
What is the difference between Euclidean and Manhattan distances?
Euclidean distance measures straight-line distance, while Manhattan distance sums absolute differences along each axis, like moving along grid lines.
Click to reveal answer
Which distance metric measures the straight-line distance between two points?
ACosine distance
BEuclidean distance
CManhattan distance
DHamming distance
✗ Incorrect
Euclidean distance is the straight-line distance between two points.
Which distance metric focuses on the angle between two vectors?
ACosine distance
BEuclidean distance
CManhattan distance
DJaccard distance
✗ Incorrect
Cosine distance measures similarity based on the angle between vectors.
Manhattan distance is best described as:
ASum of squared differences
BDifference of angles
CMinimum distance
DSum of absolute differences
✗ Incorrect
Manhattan distance sums the absolute differences of coordinates.
Which scipy function calculates Euclidean distance?
2. Which of the following is the correct way to import the Euclidean distance function from scipy?
easy
A. from scipy.spatial.distance import euclidean
B. import scipy.distance.euclidean
C. from scipy.distance import euclidean
D. import euclidean from scipy.spatial
Solution
Step 1: Recall scipy import syntax
The correct import path for distance functions is scipy.spatial.distance.
Step 2: Check each option
from scipy.spatial.distance import euclidean uses correct syntax: from scipy.spatial.distance import euclidean. Others are invalid or incorrect syntax.
Final Answer:
from scipy.spatial.distance import euclidean -> Option A
Quick Check:
Correct import path = from scipy.spatial.distance import euclidean [OK]
Hint: Use 'from scipy.spatial.distance import' for distance functions [OK]
Common Mistakes:
Using wrong module path
Incorrect import syntax
Trying to import from scipy.distance
3. What is the output of this code?
from scipy.spatial.distance import cosine
v1 = [1, 0, 1]
v2 = [0, 1, 0]
result = cosine(v1, v2)
print(round(result, 2))
medium
A. 1.0
B. 0.5
C. 0.0
D. 0.71
Solution
Step 1: Calculate cosine similarity basics
Vectors v1 and v2 are orthogonal (no overlap), so cosine similarity is 0.
4. Find the error in this code snippet calculating Manhattan distance:
from scipy.spatial.distance import manhattan
a = [1, 2, 3]
b = [4, 5]
print(manhattan(a, b))
medium
A. Function name should be cityblock, not manhattan
B. Import statement is incorrect
C. Lists a and b must be the same length
D. Manhattan distance requires numpy arrays, not lists
Solution
Step 1: Check input vector lengths
Vectors a and b have different lengths (3 and 2), which is invalid for distance calculation.
Step 2: Validate function and import
Import and function name are correct; scipy.spatial.distance.manhattan is valid and accepts lists.
Final Answer:
Lists a and b must be the same length -> Option C
Quick Check:
Equal length vectors needed for distance [OK]
Hint: Vectors must be same length for distance functions [OK]
Common Mistakes:
Assuming different length lists work
Confusing function name with cityblock
Thinking lists are invalid inputs
5. You have two points: p1 = [3, 4, 5] and p2 = [1, 1, 1]. Which distance metric will give the largest value? Options: A) Euclidean B) Cosine C) Manhattan D) All equal