Unsupervised Learning - Kmeans Week 11 Challenge
Calculating similarity for categorical data involves different approaches compared to numerical data. Here are some common methods for measuring similarity between categorical variables:
1. Hamming Distance
Hamming distance measures the number of positions at which the corresponding elements are different. It is used when the data is categorical, and the variables are of equal length.
- Formula:
- Where:
- and are the values at position i in the two strings.
- is an indicator function that equals 1 if the condition is true and 0 otherwise.
2. Jaccard Similarity
Jaccard similarity measures the proportion of shared attributes between two sets.
- Formula:
- Where:
- and are sets of attributes.
- is the number of common attributes.
- is the number of total unique attributes.
3. Cosine Similarity
Cosine similarity measures the cosine of the angle between two vectors. For categorical data, you typically convert categories into binary vectors.
- Formula:
- Where:
- and are vectors representing the categorical attributes.
- is the dot product.
- denotes vector norm.
4. Matching Coefficient
The matching coefficient measures the similarity by counting the number of matching attributes between two categorical records.
- Formula:
5. Dice's Coefficient
Dice's coefficient is similar to Jaccard but gives more weight to matches.
- Formula:
- Where:
- and are the sizes of sets and , respectively.
6. Kullback-Leibler Divergence
Used for comparing probability distributions, it can also be applied to categorical data by treating them as probability distributions.
- Formula:
- Where:
- and are probability distributions over categorical attributes.
Explanations and Business Insights
Customer Segmentation:
Clusters: The clusters represent different segments of customers based on their car features.
Insight: For example, one cluster might represent customers who prefer high-end cars with high horsepower, while another might represent budget-conscious customers who prioritize fuel efficiency.
Product Positioning:
Analysis: By examining the average features in each cluster, you can understand how different car features are valued.
Insight: You might find that one cluster values high engine size and horsepower, indicating a preference for performance cars.
Marketing Strategies:
Strategy: Tailor marketing campaigns to each cluster's preferences.
Insight: High-end car features can be highlighted in campaigns targeting clusters that value luxury, while fuel efficiency can be emphasized for budget-focused clusters.
Inventory Management:
Inventory: Adjust stock based on cluster preferences.
Insight: If a cluster with a large market share prefers cars with high horsepower, ensure adequate inventory of performance models.
Example Output
Elbow Method Plot:
Helps determine the optimal number of clusters by plotting the distortion score against the number of clusters.
Cluster Summary:
Shows average feature values for each cluster, helping to profile each customer segment.
Scatter Plots:
Visualize how clusters differ based on features like MPG City vs. Horsepower and Weight vs. Engine Size.
Silhouette Score:
Indicates how well-separated the clusters are. A higher score means better-defined clusters.