【发布时间】:2019-12-01 16:58:59
【问题描述】:
基本上我对 527*38(行 x 列)的数据集使用 K-means。 我想使用 K-means 并且我已经设置了 3 个集群,但我无法在 3D 维度中对其进行可视化。如果有人可以帮助我尝试过,我会展示它
我已将我的数据集 x4 转换为列表
下面是代码
from sklearn.cluster import KMeans
# Number of clusters
kmeans = KMeans(n_clusters=3)
# Fitting the input data
kmeans = kmeans.fit(x4)
# Centroid values
c = kmeans.cluster_centers_
import numpy as np
x4=np.array(x4)
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure()
ax = Axes3D(fig)
ax.scatter(x4[:, 0], x4[:, 1], x4[:, 2])
ax.scatter(c[:, 0], c[:, 1], c[:, 2], marker='*', c='#050505', s=1000)
尝试用 3d 绘图 我附上了我得到的输出图像
这是预期的输出图像。像这样的东西是我需要 3 个集群
【问题讨论】: