Data Mining Exercise 3
An overview of Data Mining (DM), its techniques, applications, and challenges.
Warning
This article is a work in progress and may contain incomplete information or inaccuracies. Please verify details from reliable sources.
Data Mining Exercise 3
📏 Distance & Similarity Measures
💡 Core Concept
These mathematical formulas (Distance & Similarity Measures) are like a "ruler" in the world of Data Mining.
If we don't have these "rulers", the computer won't know how "similar" or "different" data A is from data B.
And if it doesn't know similarity/difference, it cannot do:
- 📊 Clustering
- 🎯 Recommendation
Let's look at calculations with "Real-world Scenarios (Use Cases)" that will make you see the clear picture.
📝 Problem 2.1: Data in the same direction, but different magnitude
Input: and
🧮 1. Calculation
📐 Euclidean Distance
Cosine Similarity
📈 Correlation
Important
Since values in are all equal (Variance = 0) and are all equal, finding Correlation will result in divide by zero (Undefined).
Meaning in Data Mining: Cannot find linear relationship because data does not change at all (Flat line).
🌍 2. Real-world Scenario
Context: Analyzing word frequency in documents (Text Mining)
Suppose vectors represent frequency of words "Data", "Mining", "KDD", "AI" in documents:
- Document x: Each word 1 time (Short abstract)
- Document y: Each word 2 times (Full article, same content as x but twice as long)
🎯 Key Takeaway
- Euclidean = 2 (Far apart): Says "These two files are not the same length"
- Cosine = 1 (Exactly the same): Says "These two files talk about exactly the same thing!"
💡 Application:
If you build a Search Engine or Plagiarism Detection, you should use Cosine because we care about "content", not the "length" of the document.
📝 Problem 2.2: Binary data (0/1) that are opposite
Input: and
🧮 1. Calculation
📐 Euclidean Distance
📊 Cosine Similarity
📌 Note
Dot product of 0 means perpendicular or no similarity at all.
🔗 Jaccard Similarity
- M₁₁ (Both have 1) =
0 - M₀₁ or M₁₀ (Only one has 1) =
4
📈 Correlation
Calculated to be -1.0 (Perfect Negative Correlation) because when is 1, is always 0 (opposite direction).
🌍 2. Real-world Scenario
Context: Recommender System or Market Basket Analysis
Suppose vectors represent buying 4 items: {Milk, Beer, Diapers, Snacks}
- Customer x: Bought (Beer, Snacks) →
(0,1,0,1) - Customer y: Bought (Milk, Diapers) →
(1,0,1,0)
🎯 Key Takeaway
- Jaccard = 0: Says "These two people do not buy any of the same items" (used to filter out unalike people)
- Correlation = -1: Goes deeper saying "The tastes of these two people are completely opposite"
💡 Application:
In KDD, if we want to do Clustering (grouping customers):
- ✅ If using Euclidean → Distance is 2 (seems not a lot)
- ✅ If using Jaccard or Cosine → Will clearly state it is 0 (clearly different groups)
⚡ Conclusion
For Sparse data (data with many 0s) like shopping baskets, Jaccard or Cosine often work better than Euclidean.
🔄 Summary of relation to KDD Process
These formulas are the Engine working behind the scenes of Data Mining steps.
1️⃣ Preprocessing Step
🔍 Deduplication:
- Question: How do we know if 2 customer records in the database are the same person with a typo?
- Solution: Use String Similarity (similar to Cosine/Jaccard) to compare characters. If similar > 90%, merge them.
2️⃣ Data Mining Step
📊 Clustering (e.g. K-Means):
- The algorithm must know which point is "closest" to the center.
- Must use Euclidean Distance to measure distance to group data together.
🎯 Classification (e.g. K-Nearest Neighbors - KNN):
- Will guess which group a new customer belongs to.
- Must find the "nearest neighbors" (first 5 people) by using these Distance formulas to measure who is closest.
📋 Decision Guide Summary Table
| Formula | Focus | Application | | ------
-------- | ---------------------------------- | --------------------------------------------------------------------------- | | Euclidean | Measures physical distance | General continuous numerical data, geographical distance (GPS) | | Cosine | Measures direction (ignores magnitude) | Text Mining (documents), search, user profile comparison | | Jaccard | Measures set overlap | Market Basket Analysis, Binary data (0/1) | | Correlation| Measures linear relationship | Stock analysis, finding Feature relationships (Feature Selection) |