I've recently entered the realm of machine learning and a project I am working on requires me to cluster users based on the order they visited webpages on a website. I have data in the form of:

['user_id', 1, 2, 4, 6, 3, 7, 3, 2, 4...]

Where each number is a category/page that the user visited. In addition the length of data for each user is not the same i.e. some users visit more pages than others.

I realize this is really vague and defining similarity it hard. I tried following the example in this research paper and to be honest a lot of it went over my head.

I need help in how to approach this problem and am open to new ideas and suggestions.


2 Answers 2


It is a good question with many practical applications.

Your data are sequential so we need a similarity measure between any pair of sequences. I recommend Levensthein distance since it is very intuitive and very nicely defined. See also this nice bachelor thesis with an overview of more measures for sequential data.

Finally, if one has the distances between all pairs of sequences, we can use any clustering algorithm that takes a distance matrix as input (for example any hierarchical algorithm).


You can use package clickstream or clickclust in R language. It performs exactly what you are looking for.

  • 2
    $\begingroup$ This is really better suited as a comment than an answer. $\endgroup$
    – Silverfish
    Commented Jul 27, 2016 at 13:08

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.