Challenge

Unsupervised Learning - Kmeans Week 11 Challenge

Que1. How does similarity is calculated if data is categorical in nature

Ans.

Hamming Distance:

  • Hamming distance measures the number of positions at which the corresponding symbols in two strings are different.
  • It is primarily used for strings of equal length, where each position represents a categorical attribute.
  • For example, if you have two categorical vectors "AAB" and "ABB," the Hamming distance is 1 because they differ in the second position.

Jaccard Similarity:

  • Jaccard similarity is used for comparing the similarity and diversity of sample sets.
  • For categorical data, you can represent each data point as a set of categories, and then compute the Jaccard similarity between two sets.
  • The Jaccard similarity is calculated as the size of the intersection divided by the size of the union of the sets.

Levenshtein Distance (Edit Distance):

  • Originally designed for strings, the Levenshtein distance can be adapted for categorical data by treating each category as a character.
  • It measures the minimum number of single-character edits (insertions, deletions, or substitutions) required to change one string into the other.

Categorical Cross-Entropy:

  • Commonly used in the context of classification problems, categorical cross-entropy measures the dissimilarity between two probability distributions over the same set of categories.
  • It is often used when dealing with categorical variables that are represented as one-hot encoded vectors.

Minkowski Distance:

  • Minkowski distance is a generalization of various distance metrics, including Euclidean distance and Manhattan distance.
  • When dealing with categorical data, Minkowski distance can be used with a parameter (p) that adjusts the sensitivity to differences. Setting p=1 corresponds to Manhattan distance, and p=2 corresponds to Euclidean distance.

Que.2 Implement K-means for “Car dataset” and come up with the business insights

Ans. There were a lot of car related datasets so I decided to take car mileage dataset which I used for PCA.

- The data was imported and WCSS (or) SSE was done to perform the elbow method to find the optimum number of cluster.

The optimal value seems to be 6.

- Then the model was trained for 6 clusters and multiple graphs we plotted to observe each feature's influence on Mileage.

from these graphs we can arrive at few conclusions:

- the relationship between horse power, sp and mileage are very clear. the higher the value the lesser the mileage.

- weight and volume don't seem to follow a simple correlation with mileage like the other 2. They appear to be the peripherals which affects the other 2 features relationship with mileage. however the data points with more mileage lie between the average values of the 2 features.

- The cars with more mileage seem to focus Less on HP and SP , and finds a balance between weight and volume to achieve the mileage.

- The cars with more horse seem to achieve a little more mileage by sacrificing volume and reducing weight.

Insights:

If a company wants to achieve maximum fuel economy they have to focus mainly on HP and SP. If thier target audience does'nt care about space then they can reduce volume which with proportionally reduce weight and can increase the mileage of the vehicle.

(the program and data files are attached below.)

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.