关于 python:Elbow Plot – ValueError: x and y must have the same first dimension | 珊瑚贝

Elbow Plot – ValueError: x and y must have same first dimension

本问题已经有最佳答案,请猛点这里访问。


我想为从 excel 文件中读取的预处理数据集生成肘部图。在下一步中,我想使用 matplotlib 包中的 plot 方法生成一个肘部图。执行代码后出现以下错误:

1
ValueError: x and y must have same first dimension, but have shapes (10,) and (1,)

代码如下所示:

1
2
3
4
5
6
7
plt.plot(range(1, 11), wcss, linewidth = 4, color = ‘black’, marker = ‘D’, markersize = 10)
plt.title(‘The Elbow Method’, family = ‘Arial’, fontsize = 14, color = ‘black’)
plt.xlabel(‘Number of Clusters’, family = ‘Arial’, fontsize = 12, color = ‘black’)
plt.ylabel(‘WCSS’, family = ‘Arial’, fontsize = 12, color = ‘black’)
plt.xticks(fontsize = 12, color = ‘black’)
plt.yticks(fontsize = 12, color = ‘black’)
plt.grid(which = ‘both’, color = ‘black’, axis = ‘x’, alpha = 0.5)

问题可能出在哪里?


请注意,在 x 轴上,您正在绘制 10 个点(即 range(1,11)),但在您的 wccs 变量中似乎只有一个值,您必须匹配 x 和 y 的数字,您十个不同的\\’x\\’不能有1个\\’y\\’。根据需要重新查看并调整 wccs 中的范围或值。


变量 wcss 似乎是一个标量而不是一个向量。

如果不知道您是如何创建变量 wcss 的,我们无法真正回答这个问题。但是您可能应该看看那个变量。


来源:https://www.codenong.com/63826108/

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_9189.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?