Clustering customers by their orders sequence patterns I have dataset with clients orders.  Example: 
Customer_1 07.06.2017 Order_1 Product_1
Customer_1 15.06.2017 Order_2 Product_2
Customer_1 01.09.2017 Order_2 Product_1
Customer_2 07.05.2017 Order_3 Product_3
Customer_2 07.06.2017 Order_4 Product_2
Customer_2 25.09.2017 Order_5 Product_3
Customer_2 05.12.2017 Order_5 Product_1
....
Customer_N

How can I cluster these customers behavior? This dataset looks like time series. But It's difficult for me to find the right way for solving this problem. The history of each customer has different length. And I can't use simple clustering algorithms.
My major aim is to distinguish different customer behaviors, find persons who have started buy more frequently, who have changed their preferences in products (started buy other products), who have tried new for them products but back to previous products. How can I cluster patterns of behavior?
 A: If you can discretize the event at each time moment "t" to some discrete (1 of M) value, you can apply the probabilistic Markov Mixture model. The model is fit using only the data (sequences), no labels are needed.
The Markov Mixture model clusters sequence data into predefined number of clusters, K. Each cluster is modeled using a square transition matrix which is learned by the algorithm. Also the algorithm learns initial state probabilities as well as cluster proportions.
Once the model is trained, the same model can be used to predict the cluster assignments as probabilities. Confident cluster assignments will have almost all mass for one of the clusters; not confident assignments will have probability mass distributed across multiple (if not most) clusters. You can compute entropy to find the reliable estimates and the difficult ones.
I have some work in progress implementation of the model in C# using Infer.NET probabilistic programming framework. The code is on GitHub: https://github.com/usptact/MarkovMixtureModel
I suggest to find a tutorial on Markov Mixture models to gain better understanding how it works. With some effort, you can implement it in your favorite language.
For your application, I see two hurdles before you can use the model:


*

*how to pick the discrete states?

*how to pick the number of clusters?
For the former, the states can be product category the purchased item belongs to. Say, if at moment "t" the person buys "can of pepsi", you can encode it with a state describing "Soda Drinks". The trick is not to have too many states as you would need exponentially more data to train your model on.
For the latter, you can sweep the range of cluster values and pick the one for which the model has the highest evidence. The Bayesian probabilistic models naturally provide this probability.
