I have 100 people with their mobile browsing records, where each record tracks the person's browsing url and duration etc., and thus each person will have multiple rows of records.

Now I want to cluster the 100 ppl based on their records using K-prototypes(a combination of kmeans and kmodes) algorithm, but the problem is that each row of the data is not equivalent to one person. so how should I approach to this problem?

Any suggestions or ideas?

  • $\begingroup$ k-means is generally a poor choice for clustering, & will be especially poor here. You shouldn't use k-means with categorical data, it is only a way to minimize (squared) euclidean distances, which aren't appropriate for categorical data. Please read some of the existing threads on k-means on the site. $\endgroup$ Commented Jan 8, 2022 at 1:28
  • $\begingroup$ Hi Monica, Thank you for your reply. regarding the categorical data, I was thinking to use K-prototypes algorithm instead of K-means. But I don't fully understand "k-means is generally a poor choice for clustering", could you elaborate more regarding this please? $\endgroup$ Commented Jan 8, 2022 at 1:39
  • $\begingroup$ You should read through some of the existing threads on the site. $\endgroup$ Commented Jan 8, 2022 at 1:58

1 Answer 1


I am assuming that the session id unique in your dataset, hence why there are multiple user ids across observations.

To answer your question, you are going to need to create new categorical features which encapsulates the urls each user visited, and new features which encapsulate the aggregated duration for the corresponding url, so that each row represents all the information for each user id

  • $\begingroup$ Hi Thank you for your reply. Yes, each row is indexed by session id, and there are a few categorical features in each example/row. I totally agree with what you suggested, basically by feature engineering, to aggregate those rows into one row for each user, then proceed with the model. $\endgroup$ Commented Jan 8, 2022 at 1:32
  • $\begingroup$ But the problem is by feature engineering, it is very likely that some information would be discarded or ignored as I noticed the categorical features have high cardinality. Thus I am wondering if there are more feasible or smarter way to approch this problem? offhand, I can think of clustering each session instead of user, then based on the grouped sessions to determine the characteristics of users, but not sure if this is valid thinking. For your advice please. $\endgroup$ Commented Jan 8, 2022 at 1:33

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.