sklearn中的Silhouette Score功能发出意外错误

时间:2015-09-14 19:43:00

标签: numpy pandas scikit-learn

我正在尝试对数据运行Kmeans群集。我的数据框是一个pandas数据框,具有以下维度。

People_reduced.shape
Out[155]:
(417837, 13)

现在,当k-means运行正常时,当我尝试将Kmeans集群标签的输出和原始数据框提供给sklearn的silhouette_score方法时,它会抛出一个奇怪的错误。

以下是我使用的代码:

kmeans=KMeans(n_clusters=2,init='k-means++',n_init=10, max_iter=20)
kmeans.fit(People_reduced.ix[:,1:])
cluster_labels = kmeans.labels_
    # The silhouette_score gives the average value for all the samples.
    # This gives a perspective into the density and separation of the formed
    # clusters
silhouette_avg = silhouette_score(People_reduced.ix[:,1:].values,cluster_labels)

错误:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-154-b392e118f64a> in <module>()
     19     # This gives a perspective into the density and separation of the formed
     20     # clusters
---> 21 silhouette_avg = silhouette_score(People_reduced.ix[:,1:].values,cluster_labels)
     22 #silhouette_avg = silhouette_score(People_reduced.ix[:,1:], cluster_labels)
     23 

TypeError: 'list' object is not callable

0 个答案:

没有答案