I'm using a dataset with customer card transactions to solve a clustering problem.
On a first approach, I'm trying K-means
using R packages NbClust
and cluster
My dataframe is normalized and it contains the following (sample):
as_tibble(full_dataset_log.stand)
# A tibble: 33,215 x 9
monetary frequency recency_days GENDER_F0 GENDER_F1 GENDER_FNA
<dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 0.292 -1.10 1.02 1.28 -1.28 -0.0325
2 -2.15 -1.10 0.301 1.28 -1.28 -0.0325
3 -0.905 1.15 -0.614 -0.782 0.784 -0.0325
4 0.968 1.77 -0.844 -0.782 0.784 -0.0325
5 1.90 2.06 -2.15 -0.782 0.784 -0.0325
6 1.90 2.06 -2.15 -0.782 0.784 -0.0325
7 -1.10 -0.231 -0.423 -0.782 0.784 -0.0325
8 1.55 1.77 -0.543 -0.782 0.784 -0.0325
9 0.0536 0.196 0.0471 -0.782 0.784 -0.0325
10 0.523 0.0808 0.558 -0.782 0.784 -0.0325
# ... with 33,205 more rows, and 3 more variables:
# GENDER_M0 <dbl>, GENDER_M1 <dbl>, GENDER_MNA <dbl>
>
This is the code I'm trying with 6 clusters:
k.means.fit_log <- kmeans(full_dataset_log.stand, 6)
My issue is how to deal with the GENDER
variables which have been hot-encoded:
GENDER_F0
GENDER_F1
GENDER_FNA
GENDER_M0
GENDER_M1
GENDER_MNA
They just don't seem to make sense to have as separate variables and I was wondering how I can solve this problem.
Originally, the variables were:
GENDER_M: can be 0, 1 or NA
GENDER_F: can be 0, 1 or NA
Now, on this other question I wrote that hot encoding these variables didn't work out very well. I tried:
GENDER_M0: 1 for all the records that contain 0 in column GENDER_M - 0 otherwise
GENDER_M1: 1 for all the records that contain 1 in column GENDER_M - 0 otherwise
GENDER_MNA: idem
GENDER_F0: idem
GENDER_F1: idem
GENDER_FNA: idem
So, in total, I have 5 possible combinations:
NA/NA
0/0
0/1
1/0
1/1
1 means that there's a presence of the respective gender in the buying patters of the customer. For example, if a customer buys razors repeatedly, he will get a 1 in column GENDER_M.
Thanks for any help, I'm quite new to R and data science!