I have some user data where each user has a certain pattern of being at different places for some time. I would like to create a model which will cluster/classify these users based on these patterns and the time spent at each place. So suppose user patterns are like:

Place_1(60 min)- Place_2(30 min)- Place_5(45 min)- user 1 -label(1)

Place_1(60 min)- Place_2(60 min)- Place_5(45 min)- user 2 -label(2)

Place_1(60 min)- Place_2(60 min)- Place_5(40 min)- user 3 -label(2)

Place_2(60 min)- Place_1(60 min)- Place_5(45 min)- user 4 -label(3)

Place_2(60 min)- Place_1(60 min)- Place_5(45 min)- user 5 -label(3)

They should be clustered/classified as:

1- User 1

2- User 2, User 3

3- User 4, User 5

The time duration is continuous. Also, I already have labels for these patterns so I can do classification as well as clustering. I initially thought of doing kmeans clustering on these patterns, but introducing the duration of stay at each place is messing the clustering up. I am currently using a random forest classifier, but the results are not as promising. Any help would be highly appreciated.

  • $\begingroup$ You could use RNN auto-encoder, hence you could use embedding layer to transform the categorical place input into a continuous dense vector, If you want to do classification just use RNN and augment the last hidden state with a linear classifier $\endgroup$ Commented May 18, 2018 at 17:32
  • $\begingroup$ Thanks, I was refraining from using neural network for this. My stack currently involves spark mllib with scala for implementing the model. I am not limiting myself to it and is certainly open to moving to neural network if thats the only plausible option. $\endgroup$ Commented May 18, 2018 at 18:41
  • $\begingroup$ if you are encoding(places as columns; time data in rows) your data properly, i don't see any problem with k means as well as randomforest. elaborate more on your problem $\endgroup$ Commented May 18, 2018 at 20:09
  • $\begingroup$ Can you please tell me what you mean by places in column and time data in column. Currently I have user record as a row where the sequence of places and time spent at the place is maintained. I cant have a concept of places with fixed column as they can come up in any order for each user. $\endgroup$ Commented May 20, 2018 at 20:11
  • $\begingroup$ random forest should work or xgboost classifier. so you need a classifier that will produce more than one output feature $\endgroup$ Commented Aug 29, 2022 at 14:33

1 Answer 1


This is commonly called spatiotemporal (ST) data clustering. Most common clustering algorithms have ST version. For example, there is ST-AGRID which adaptation of a grid density based clustering algorithm.


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.