scikit-learn - 聚类评估中的 ValueError:预期 2D 数组,得到 1D 数组
问题描述
df_2D = df[['sepal-length', 'petal-length']]
df_2D = np.array(df_2D)
k_means_2D_model = KMeans(n_clusters=3, max_iter=1000).fit(df_2D)
错误:
ValueError: Expected 2D array, got 1D array instead:
array=[0 1 0 0 2 2 1 2 1 1 0 1 0 2 0 2 1 2 0 2 2 1 0 1 2 0 0 2 1 0 2 0 1 1 0 0 2
1 2 1 0 0 1 1 1 1 2 1 2 2 0 2 2 2 0 1 1 1 1 0 1 2 1 2 1 2 2 1 2 1 0 0 2 1
1 0 2 0 0 1 1 0 1 2 1 1 0 1 0 1 0 0 0 2 1 1 1 2 0 2 0 0 2 2 0 0 1 2 2 1 0
2 2 1 1 2 0 0 2 2 2 0 0 1 0 1 0 2 2 2 0 0 0 0 2 1 2 2 2 2 1 1 1 2 2 0 0 0
1 0].
Reshape your data either using array.reshape(-1, 1) if your data has a single feature or array.reshape(1, -1) if it contains a single sample.
解决方案
推荐阅读
- javascript - 使用新插入的内容滚动到 div 的底部
- linux - 创建 Lightsail 实例并安装 CodeDeploy 代理
- vue.js - 更改 element-ui Select 中的图标
- python - 为什么我的石头剪刀布游戏不启动while循环?
- jenkins - 如何在詹金斯中获得并行构建作业结果
- python - 美丽的汤没有找到基本的 HTML 数据
- node.js - Package.json 有一个实际上不存在的 Package 版本。怎么了?
- reactjs - 如何避免反应日期选择器日历在上一个文本框中的选项卡按键上打开
- django - 如何在 Django 中使用带问号的 URL 执行查询?
- android - Lazy initialization with repository