如何在python中使用KMeans对时间序列进行聚类

时间:2016-02-09 04:02:21

标签: python numpy pandas machine-learning scikit-learn

所以我有[UID obj1 obj2 ..] x时间戳形式的数据,我想使用sklearn中的kmeans在python中聚集这些数据。我应该从哪里开始?

编辑:

所以基本上我试图根据点击流数据对用户进行聚类,并根据使用模式对用户进行分类。

2 个答案:

答案 0 :(得分:0)

您可以根据原始数据添加更多功能,并使用RFM Analysis等方法。 RFM =新近度,频率,货币

例如:

How often the user logged in?

The last time the user logged in?

答案 1 :(得分:0)

您可以使用Python库Fisher-Yates shuffleRetentioneering),该库允许您通过简单的命令基于点击流数据对用户进行聚类。您还可以指定您对集群感兴趣的任何目标事件,并使用交互式图形浏览获得的图形。

data.rete.get_clusters(method='kmeans',
                   feature_type='tfidf',
                   n_clusters=8,
                   ngram_range=(1,2),
                   plot_type='cluster_bar',
                   targets=['payment_done','cart']);

github

接下来,您可以使用交互式图形探索获得的行为集群:

clus_0 = data.rete.filter_cluster(0)
clus_0.rete.plot_graph(thresh=0.1,
                   weight_col='user_id',
                   targets = {'lost':'red',
                              'payment_done':'green'})

results of user clustering