Challenge - 5 Problems
Distance Metrics Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateCalculate Euclidean distance between two points
What is the output of this code that calculates the Euclidean distance between points (1, 2) and (4, 6)?
SciPy
from scipy.spatial import distance point1 = [1, 2] point2 = [4, 6] result = distance.euclidean(point1, point2) print(round(result, 2))
Attempts:
2 left
💡 Hint
Euclidean distance is the straight line distance between two points in space.
✗ Incorrect
Euclidean distance between (1,2) and (4,6) is sqrt((4-1)^2 + (6-2)^2) = sqrt(9 + 16) = sqrt(25) = 5.0.
❓ data_output
intermediateCosine distance between two vectors
What is the cosine distance between vectors [1, 0, -1] and [-1, 0, 1] using scipy?
SciPy
from scipy.spatial import distance vec1 = [1, 0, -1] vec2 = [-1, 0, 1] result = distance.cosine(vec1, vec2) print(round(result, 2))
Attempts:
2 left
💡 Hint
Cosine distance is 1 minus the cosine similarity.
✗ Incorrect
The vectors are exact opposites, so cosine similarity is -1, thus cosine distance = 1 - (-1) = 2. Scipy cosine distance returns 2 for opposite vectors.
❓ Predict Output
advancedManhattan distance calculation
What is the Manhattan distance between points (3, 5) and (1, 1)?
SciPy
from scipy.spatial import distance p1 = [3, 5] p2 = [1, 1] result = distance.cityblock(p1, p2) print(result)
Attempts:
2 left
💡 Hint
Manhattan distance sums the absolute differences of coordinates.
✗ Incorrect
Manhattan distance = |3-1| + |5-1| = 2 + 4 = 6.
❓ visualization
advancedVisualize Euclidean vs Manhattan distance
Which option correctly plots the Euclidean and Manhattan distances between points (0,0) and (3,4) on a 2D grid?
SciPy
import matplotlib.pyplot as plt import numpy as np fig, ax = plt.subplots() ax.plot([0,3], [0,4], label='Euclidean') ax.plot([0,3,3], [0,0,4], label='Manhattan') ax.scatter([0,3], [0,4], color='red') ax.legend() plt.show()
Attempts:
2 left
💡 Hint
Manhattan distance looks like walking along grid streets, Euclidean is straight line.
✗ Incorrect
Euclidean distance is the straight line connecting points. Manhattan distance is the sum of horizontal and vertical moves, forming an L shape.
🧠 Conceptual
expertUnderstanding cosine distance range
Which statement about cosine distance computed by scipy.spatial.distance.cosine is correct?
Attempts:
2 left
💡 Hint
Recall cosine distance = 1 - cosine similarity.
✗ Incorrect
Cosine similarity ranges from -1 (opposite) to 1 (identical). Cosine distance = 1 - cosine similarity, so it ranges from 0 (identical) to 2 (opposite).
