3

I recently started working on clustering and k-means algorithm and was trying to come up with a good use case and solve it.

I have the following data about the items sold in different cities.

Item City

Item1 New York
Item2 Charlotte
Item1 San Francisco
...

I would like to cluster the data based on variables city and item to find groups of cities that might have similar patterns for the items sold.The problem is the k-means I use do not accept non-numeric input. Any idea how should I proceed with this to find a meaningful solution.

Thanks SV

3 Answers 3

3

Clustering requires a distance definition. A cluster is only a cluster if the items are "closer" according to some distance function. The closer they are, the more likely they belong to the same cluster.

In your case, you can try to cluster based on various data related to the cities, like their geographical coordinates, or demographic informations, and see if the clusters overlap in the various cases !

2

In order for k-means to produce usable results, the means must be meaningful.

Even if you would e.g. use binary vectors, k-means on these would not make a lot of sense IMHO.

Probably the best use case to get started with k-means is color quantization. Take a picture, and use the RGB values of every pixel as 3d vectors. Then run k-means with k as the desired number of colors. The color centers are your final palette, and every pixel will be mapped to the closest center for color reduction.

The reason why this works well with k-means are twofold:

  • the mean actually makes sense for finding the mean color of multiple pixels
  • the axes R, G and B have a similar meaning and scale, so there is no bias

If you want to step beyond, try to do the same e.g. in HSB space. And you'll run into difficulties if you want it to be really good. Because the hue value is cyclic, which is inconcistent with the mean. Assuming the hue is on 0-360 degrees, then the "mean" hue of "1" and "359" is not 180 degrees, but 0. So on this data, k-means results will be suboptimal.

See e.g. https://en.wikipedia.org/wiki/Color_quantization for details as well as the two dozen k-means questions here with respect to sparse and binary data.

0

You may still need to abstractly represent your data in numerical form. This May Help

http://www.analyticbridge.com/forum/topics/clustering-with-non-numeric?commentId=2004291%3AComment%3A40805

Try to re-analyze the problem again and Understand if there is any relationship that you can take advantage of and represent in numerical form. I worked on a Project where I had to represent Colors by their RGB values. It worked preety good.

Hope this helps

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.