【发布时间】:2021-07-11 19:08:29
【问题描述】:
我正在尝试根据以下列中的信息将 k 均值应用于集群参与者
Actors Movies TvGuest Awards Shorts Special LiveShows
Robert De Niro 111 2 6 0 0 0
Jack Nicholson 70 2 4 0 5 0
Marlon Brando 64 2 5 0 0 28
Denzel Washington 25 2 3 24 0 0
Katharine Hepburn 90 1 2 0 0 0
Humphrey Bogart 105 2 1 0 0 52
Meryl Streep 27 2 2 5 0 0
Daniel Day-Lewis 90 2 1 0 71 22
Sidney Poitier 63 2 3 0 0 0
Clark Gable 34 2 4 0 3 0
Ingrid Bergman 22 2 2 3 0 4
Tom Hanks 82 11 6 21 11 22
#began by scaling my data
X = StandardScaler().fit_transform(data)
#used an elbow plot to find optimal k value
sum_of_squared_distances = []
K = range(1,15)
for k in K:
k_means = KMeans(n_clusters=k)
model = k_means.fit(X)
sum_of_squared_distances.append(k_means.inertia_)
plt.plot(K, sum_of_squared_distances, 'bx-')
plt.show()
#found yhat for the calculated k value
kmeans = KMeans(n_clusters=3)
model = kmeans.fit(X)
yhat = kmeans.predict(X)
无法弄清楚演员创建散点图。
编辑: 如果质心也是使用绘制的,有没有办法找到最接近质心的演员
centers = kmeans.cluster_centers_(这里的kmeans指的是下面Eric的解决方案)
plt.scatter(centers[:,0],centers[:,1],color='purple',marker='*',label='centroid')
【问题讨论】:
-
描述每个演员需要多少维度?您可以显示多少个维度才能看到某些东西?你认为你的选择是什么?您可能会受益于在Data Science 上发布您的问题,这将更适合此类问题。
-
不太确定。感谢您的堆栈交换建议
-
请注意将verbatim questions 交叉发布到多个SE 站点是not allowed;请仅在您认为您的问题更合适的地方选择一个站点,然后删除另一个站点中的帖子(事实上,目前还不清楚您的问题是什么确切 )。
标签: python-3.x pandas machine-learning data-science k-means