-1
$\begingroup$

I have non numeric data such as (city, province, gender etc) and numeric data (transaction amount etc). I ran the K-means on the continuous variable and now i want to map the non numeric variables on to these clusters. How do I do that in R? How do I tell R that these are my non numeric data and use it over clustering.

$\endgroup$
0
$\begingroup$

Not sure what you mean by “map the non numeric variables on to these clusters”. You made your clusters without those variables, therefore clusters are defined by the variables you used and any cluster assignment would be done ignoring additional variables.

What you might want to look at instead is clustering methods based on distances between points (such as K-Medoids). You’d probably want to look for some way of defining the similarity or distance between two points in your data (e.g. perhaps you can compare the similarity between provinces according to their average income, or whatever is relevant for your purposes), then clustering based on that.

$\endgroup$
0
$\begingroup$

Use the table() function, like this, in principle:

nclust  <- 2
# Create a k-means model on my.data: my.km
my.km <- kmeans(scale(my.data), centers = nclust)

# Compare k-means to actual categorical values
table(my.km$cluster , my.data$categval1)

Then YOU decide wether the cluster assignments make sense in this context/with this particular variable.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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