没有在 3D 中形成 38 个维度的簇
Not getting clusters formed in 3D for 38dimensions
基本上我对 527*38(行 x 列)的数据集使用 K 均值。
我想使用 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 个集群
您似乎在尝试仅使用前三个维度在 3D 绘图中绘制具有 38 个维度的数据点,这是不正确的。
要正确可视化集群,您可以尝试以下操作。
- 考虑方差最大的前 3 个维度进行绘图。
- 使用Principle Component Analysis等降维方法将38维降为3维
基本上我对 527*38(行 x 列)的数据集使用 K 均值。 我想使用 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 个集群
您似乎在尝试仅使用前三个维度在 3D 绘图中绘制具有 38 个维度的数据点,这是不正确的。
要正确可视化集群,您可以尝试以下操作。
- 考虑方差最大的前 3 个维度进行绘图。
- 使用Principle Component Analysis等降维方法将38维降为3维