在38维中未形成3D群集

基本上,我使用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绘图 我已经附上我得到的输出图像

在38维中未形成3D群集

这是预期的输出图像。我需要3个集群

在38维中未形成3D群集

yangyong1001 回答:在38维中未形成3D群集

看起来您正在尝试仅使用前三个维度来绘制3D图中具有38个维度的数据点。

要正确可视化群集,可以尝试以下操作。

  1. 考虑绘图变化最大的前3个维度。
  2. 使用诸如Principle Component Analysis之类的尺寸缩减方法将38尺寸缩减为3尺寸。
本文链接:https://www.f2er.com/3032045.html

大家都在问