Challenge

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: Hamming Distance=∑i=1nI(xi≠yi)
  • Where:
    • xix_iand yiy_i are the values at position iii in the two strings.
    • I\text{I}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: Jaccard Similarity=∣A∩B∣∣A∪B∣\text{Jaccard Similarity} = \frac{|A \cap B|}{|A \cup B|}​
  • Where:
    • AA and BB are sets of attributes.
    • ∣A∩B∣|A \cap B| is the number of common attributes.
    • ∣A∪B∣|A \cup B| 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: Cosine Similarity=A⋅B∥A∥∥B∥\text{Cosine Similarity} = \frac{A \cdot B}{\|A\| \|B\|}​
  • Where:
    • AA and BB are vectors representing the categorical attributes.
    • ⋅\cdot is the dot product.
    • ∥⋅∥\| \cdot \| denotes vector norm.

4. Matching Coefficient

The matching coefficient measures the similarity by counting the number of matching attributes between two categorical records.

  • Formula: Matching Coefficient=Number of Matching AttributesTotal Number of Attributes\text{Matching Coefficient} = \frac{\text{Number of Matching Attributes}}{\text{Total Number of Attributes}}​

5. Dice's Coefficient

Dice's coefficient is similar to Jaccard but gives more weight to matches.

  • Formula: Dice’s Coefficient=2⋅∣A∩B∣∣A∣+∣B∣\text{Dice's Coefficient} = \frac{2 \cdot |A \cap B|}{|A| + |B|}​
  • Where:
    • ∣A∣|A| and ∣B∣|B| are the sizes of sets AA and BB, 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: DKL(P∥Q)=∑iP(i)log⁡P(i)Q(i)D_{KL}(P \| Q) = \sum_{i} P(i) \log \frac{P(i)}{Q(i)}​
  • Where:
    • PP and QQ 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.

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.