Unsupervised Learning - Kmeans Week 11 Challenge
- How does similarity is calculated if data is categorical in nature
1. Hamming Distance
-
Used when categorical variables are binary (0/1, Yes/No, True/False).
-
It calculates the number of positions at which two strings of equal length are different.
-
Formula:
d(x,y)=i=1∑nI(xi=yi)where I(xi=yi) is 1 if xi=yi, otherwise 0.
2. Jaccard Similarity
-
Used for categorical variables, especially nominal data (e.g., colors, product categories).
-
Measures the ratio of common elements to total unique elements.
-
Formula:
J(A,B)=∣A∪B∣∣A∩B∣ -
Example: If A = {red, blue, green} and B = {blue, green, yellow}, then
J(A,B)=42=0.5
3. Simple Matching Coefficient (SMC)
-
Similar to Jaccard but includes both matches (1-1 and 0-0) in similarity calculation.
-
Formula:
SMC=a+b+c+da+dwhere:
-
a = Number of attributes where both objects have 1 (Yes-Yes)
-
d = Number of attributes where both objects have 0 (No-No)
-
b, c = Number of mismatches
-
4. Gower’s Similarity Coefficient
-
Works for mixed data types (numerical + categorical).
-
Computes similarity for each feature separately and averages them.
5. One-Hot Encoding + Cosine Similarity
-
Convert categorical data into binary vectors using one-hot encoding.
-
Compute cosine similarity between vectors:
cos(θ)=∥A∥∥B∥A⋅B
6. Levenshtein Distance (Edit Distance)
-
Measures similarity between strings by counting minimum operations (insert, delete, replace) to convert one string into another.
2. Implement K-means for “Car dataset” and come up with the business insights
📊 METRICS USED
We extracted and cleaned multiple car specifications, then engineered some key features:
1. Mileage (kmpl or km/kg)
-
Extracted from
ARAI_Certified_Mileage,Highway_Mileage, andCity_Mileage. -
Higher mileage = more fuel efficiency.
2. Power & Torque
-
Cleaned using regex from strings like "100 bhp @ 4000 rpm".
-
Indicates engine strength and pulling capacity.
3. Ex-Showroom Price (₹)
-
Cleaned by removing symbols and converted to float.
-
Proxy for affordability and segment.
4. Number of Airbags & Safety Rating
-
Measures passenger safety.
-
Included in scoring and purchasing capacity.
5. Composite Score
-
Normalized features and computed average score for ranking cars.
-
Inverted price since low price is more desirable.
6. Cluster (KMeans)
-
Cars were grouped using KMeans clustering based on normalized features:
-
"Ex-Showroom_Price", "Mileage", "Power", "Torque", "Number_of_Airbags"
-
-
PCA was used for 2D visualization of clusters.
7. Purchasing Capacity
-
Proxy indicator =
0.6 * Price + 0.2 * Power + 0.2 * Number_of_Airbags -
Used for evaluating affordability by cluster.
📈 GRAPHS AND VISUALIZATIONS
1. Top 10 Cars by Composite Score
-
Displayed cars ranked using normalized metrics.
-
Helped identify value-for-money cars with balance between performance, safety, and price.
2. KMeans Cluster Plot (PCA1 vs PCA2)
-
Each car visualized in 2D space after PCA dimensionality reduction.
-
Clusters show natural groupings like:
-
Cluster 0: Budget & fuel-efficient
-
Cluster 1: Mid-range all-rounders
-
Cluster 2: Premium/high-performance
-
Cluster 3: Luxury/flagship models
-
3. Cluster Pie Chart
-
Distribution of cars by cluster.
-
Showed which cluster has the most cars (e.g., mid-range dominating).
4. Sales by Make
-
Bar chart showing how many cars are sold for each car brand.
-
Helpful to see brand popularity (e.g., Maruti, Hyundai leading).
5. Purchasing Capacity by Cluster (Pie Chart)
-
Visualized which cluster contributes most to total purchasing capacity.
-
Luxury/premium clusters contribute more even with fewer cars.
✅ CONCLUSIONS
1. Mileage vs Power Tradeoff
-
Budget cars have high mileage but low power.
-
Premium cars sacrifice mileage for performance.
2. Cluster Insights
-
Majority cars fall in mid-range/budget segment (Clusters 0 and 1).
-
Cluster 3 has fewer cars but significantly higher purchasing power.
3. Top Performing Cars
-
Some mid-price cars (e.g., from Hyundai, Maruti) scored high due to a good balance of features, safety, and price.
4. Brand Popularity
-
Brands like Maruti Suzuki and Hyundai have higher representation, suggesting market penetration.
5. Feature-Rich Cars Don't Always Mean High Score
-
Overpriced vehicles with imbalanced features scored lower.
-
Normalization helped avoid skewing scores by high price.