嗨,我在查看kmeans聚类结果时遇到类型错误unhashable type: 'numpy.ndarray'
。我不确定是因为我的数据是数据框吗?
我的数据看起来像这种格式
df3
A B C D E
1 FALSE FALSE FALSE FALSE FALSE
2 TRUE FALSE FALSE FALSE FALSE
3 FALSE FALSE FALSE FALSE FALSE
4 FALSE FALSE FALSE TRUE FALSE
5 FALSE FALSE FALSE FALSE FALSE
6 FALSE FALSE FALSE FALSE FALSE
7 FALSE FALSE TRUE FALSE FALSE
8 TRUE FALSE TRUE FALSE FALSE
9 FALSE FALSE FALSE FALSE TRUE
10 FALSE TRUE FALSE TRUE TRUE
代码
fig= plt.figure(figsize=(8, 3))
fig.subplots_adjust(left=0.02, right=0.98, bottom=0.05, top=0.9)
colors= ['#4EACC5', '#FF9C34', '#4E9A06']
k_means_cluster_centers= np.sort(k_means.cluster_centers_, axis=0)
k_means_labels= pairwise_distances_argmin(df3, k_means_cluster_centers)
ax= fig.add_subplot(1, 3, 1)
for k, col in zip(range(n_clusters), colors):
my_members= k_means_labels == k
cluster_center= k_means_cluster_centers[k]
ax.plot(df3[my_members, 0], df3[my_members, 1],'w', markerfacecolor=col, marker='.')
ax.plot(cluster_center[0], cluster_center[1],'o', markerfacecolor=col, markeredgecolor='k', markersize=6)
ax.set_title('KMeans')
ax.set_xticks(())
ax.set_yticks(())
plt.text(-3.5, 1.8, 'inertia= %f' % (k_means.inertia_))
plt.show()
类型错误
TypeError Traceback (most recent call last)
<ipython-input-172-7f988487d56c> in <module>()
10 my_members= k_means_labels == k
11 cluster_center= k_means_cluster_centers[k]
---> 12 ax.plot(df3[my_members, 0], df3[my_members, 1],'w', markerfacecolor=col, marker='.')
13 ax.plot(cluster_center[0], cluster_center[1],'o', markerfacecolor=col, markeredgecolor='k', markersize=6)
请问有关如何解决此问题的任何建议?