Lecture: Lecture 08 - Data Preprocessing
Proximity
Similarity measures how alike two objects are; larger usually means more alike. Dissimilarity or distance measures how different they are; smaller usually means more alike.
The right measure depends on the data type and the question.
Numeric distances
Euclidean distance is straight-line distance:
d(x,y) = sqrt(sum((xk - yk)^2))For x=(2,3) and y=(5,7):
d = sqrt((2-5)^2 + (3-7)^2) = sqrt(25) = 5Minkowski distance generalizes several choices:
r=1: Manhattan distance;r=2: Euclidean distance;rapproaching infinity: largest coordinate difference.
Normalize attributes first when their units differ. Otherwise income can overwhelm age or study hours simply because its numbers are larger.
Binary and document comparisons
For binary attributes, define M11 as both 1, M10 and M01 as mismatches, and M00 as both 0.
Jaccard similarity is:
J = M11 / (M01 + M10 + M11)It ignores both-zero matches, which is useful when shared presence matters more than shared absence.
For document term vectors, cosine similarity is:
cos(x,y) = (x dot y) / (||x|| ||y||)It compares direction, so documents with similar word proportions can be similar even when one is longer.
Correlation
Correlation measures the strength and direction of a linear relationship.
- near
+1: strong upward straight-line relationship; - near
-1: strong downward straight-line relationship; - near
0: little linear relationship.
Example: study hours and exam score may have positive correlation. Distance from campus and attendance may have negative correlation.
Correlation is not causation. Ice-cream sales and sunburn cases may rise together because hot weather affects both.
Correlation also misses some nonlinear relationships. If y=x^2, the values are strongly related but the relationship is curved; positive and negative sides can cancel so Pearson correlation is near zero.
Retrieval questions
Why can distance be misleading before normalization? A large numeric scale contributes more to the formula even if it is not more important.
When is Jaccard preferable to simple matching? When joint absence is uninformative, such as comparing products that two customers purchased.
Why can correlation be zero when variables are related? Pearson correlation measures linear association, not arbitrary curves.
Does high correlation prove causation? No; a third variable or coincidence can explain the association.
Source
Elena Baralis and Tania Cerquitelli, Data preprocessing, PDF pages 59-79. Related: ElasticSearch TF-IDF Vector Space Model Semantic Embeddings and Hybrid Search. Added calculations and examples are study explanations.