Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
729 B
1
Indexable
Never
from sklearn.decomposition import PCA
from mpl_toolkits.mplot3d import Axes3D

# Выполняем PCA для уменьшения размерности до 3D
pca_3d = PCA(n_components=3)
X_reduced_3d = pca_3d.fit_transform(X_scaled)

# Визуализируем результаты в 3D
fig = plt.figure(figsize=(10, 7))
ax = fig.add_subplot(111, projection='3d')

# Визуализация каждого кластера
for i in range(k):
    ax.scatter(X_reduced_3d[y_kmeans == i, 0], X_reduced_3d[y_kmeans == i, 1], X_reduced_3d[y_kmeans == i, 2], s=50, label=f'Cluster {i}')

ax.set_title('3D PCA Visualization of Clients')
ax.set_xlabel('PCA1')
ax.set_ylabel('PCA2')
ax.set_zlabel('PCA3')
ax.legend()

plt.show()
Leave a Comment