Basic problem
Here is my basic problem: I am trying to cluster a dataset containing some very skewed variables with counts. The variables contain many zeros and are therefore not very informative for my clustering procedure - which is likely to be k-means algorithm.
Fine, you say, just transform the variables using square root, box cox, or logarithm. But since my variables are based on categorical variables, I fear that I might introduce a bias by handling a variable (based on one value of the categorical variable), while leaving others (based on others values of the categorical variable) the way they are.
Let's go into some more detail.
The dataset
My dataset represents purchases of items. The items have different categories, for example color: blue, red, and green. The purchases are then grouped together, e.g. by customers. Each of these customers is represented by one row of my dataset, so I somehow have to aggregate purchases over customers.
The way I do this is by counting the number of purchases, where the item is a certain color. So instead of a single variable color
, I end up with three variables count_red
, count_blue
, and count_green
.
Here is an example for illustration:
-----------------------------------------------------------
customer | count_red | count_blue | count_green |
-----------------------------------------------------------
c0 | 12 | 5 | 0 |
-----------------------------------------------------------
c1 | 3 | 4 | 0 |
-----------------------------------------------------------
c2 | 2 | 21 | 0 |
-----------------------------------------------------------
c3 | 4 | 8 | 1 |
-----------------------------------------------------------
Actually, I do not use absolute counts in the end, I use ratios (fraction of green items of all purchased items per customer).
-----------------------------------------------------------
customer | count_red | count_blue | count_green |
-----------------------------------------------------------
c0 | 0.71 | 0.29 | 0.00 |
-----------------------------------------------------------
c1 | 0.43 | 0.57 | 0.00 |
-----------------------------------------------------------
c2 | 0.09 | 0.91 | 0.00 |
-----------------------------------------------------------
c3 | 0.31 | 0.62 | 0.08 |
-----------------------------------------------------------
The result is the same: For one of my colors, e.g. green (nobody likes green), I get a left-skewed variable containing many zeros. Consequently, k-means fails to find a good partitioning for this variable.
On the other hand, if I standardize my variables (subtract mean, divide by standard deviation), the green variable "blows up" due to its small variance and takes values from a much larger range than the other variables, which makes it look more important to k-means than it actually is.
The next idea is to transform the sk(r)ewed green variable.
Transforming the skewed variable
If I transform the green variable by applying the square root it looks a little less skewed. (Here the green variable is plotted in red and green to ensure confusion.)
Red: original variable; blue: transformed by square root.
Let's say I am satisfied with the result of this transformation (which I am not, since the zeros still strongly skew the distribution). Should I now also scale the red and blue variables, although their distributions look fine?
Bottom line
In other words, do I distort the clustering results by handling the color green on one way, but not handling red and blue at all? In the end, all three variables belong together, so shouldn't they be handled in the same way?
EDIT
To clarify: I am aware that k-means is probably not the way to go for count-based data. My question however really is about the treatment of dependent variables. Choosing the correct method is a separate matter.
The inherent constraint in my variables is that
count_red(i) + count_blue(i) + count_green(i) = n(i)
, where n(i)
is the total number of purchases of customer i
.
(Or, equivalently, count_red(i) + count_blue(i) + count_green(i) = 1
when using relative counts.)
If I transform my variables differently, this corresponds to giving different weights to the three terms in the constraint. If my goal is to optimally separate groups of customers, do I have to care about violating this constraint? Or does "the end justify the means"?
count_red
,count_blue
andcount_green
and the data are counts. Right? What are the rows then - items? And you are going to cluster the items? $\endgroup$