0
$\begingroup$

I am working on the AdventureWorks database and I have extracted some demographic data from the person scheme as follow. My aim is to create a customer segmentation with the demographic data using the clustering technique.

businessentityid YearlyIncome Education Occupation HomeOwnerFlag
1699 25001-50000 Graduate Degree Clerical 1
1700 50001-75000 Bachelors Professional 0

Because the dataframe contains categorical data, I have decided to encode it using OneHotEncoder. The resulting table is as follows. Note that the tables and dataframes provided is just a sample in order to illustrate the idea.

encoder = OneHotEncoder(handle_unknown='ignore')
YearlyIncome_0-25000 YearlyIncome_25001-50000 Education_Graduate Degree Education_Bachelors HomeOwnerFlag_0 HomeOwnerFlag_1
0 1 0 0 1 0
1 0 0 1 0 1

Later down the line, I used Principal Component Analysis to reduce the dimensions.

pca = PCA(n_components=2)

And then applied KMeans algorithm. I experimented with elbow method to find out that the 4 is optimal n value.

kmeans = KMeans(n_clusters=4)
print(kmeans4.labels_)
array([0, 1, 3, ..., 1, 0, 2], dtype=int32)

Lastly, I combined the initial dataframe with the labels.

businessentityid Label
1699 0
1700 1
1701 3

How do I interpret the labels? There are four clusters but in the process of encoding with OneHotEncoder, the dimensions have increased and got complicated. The PCA reduced the dimensions to 2 (could be different), but how do I know what label means what? Is there something else to follow?

$\endgroup$
2
  • $\begingroup$ the labels are the clusters. so if your clustering is done correctly, entries with the same cluster labels should be very similar, like they share categories $\endgroup$
    – StupidWolf
    Commented Nov 10, 2021 at 12:28
  • 1
    $\begingroup$ Both PCA and K-means are methods generally not suitable for categorical data. Even if you turn your categories into dummy (one-hot) sets of variables. There is just no sense in doing that. $\endgroup$
    – ttnphns
    Commented Nov 11, 2021 at 16:00

0

Your Answer

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