基本上,我使用527 * 38(行x列)的数据集使用K均值。 我想使用K均值,并且设置了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],2])
ax.scatter(c[:,c[:,2],marker='*',c='#050505',s=1000)
尝试以3D绘图 我已经附上我得到的输出图像
这是预期的输出图像。我需要3个集群