python - 值错误:操作数无法与形状一起广播 (114,9) (8,) (114,9)
问题描述
我正在尝试使用 StandardScaler 缩放我的输入,这给了我一个错误
值错误:操作数无法与形状一起广播 (114,9) (8,) (114,9)
首先,我删除了测试数据集的患者,如下所示,
test = patient.iloc[2092:,0:9].values
然后我按如下方式缩放测试数据,
from sklearn.preprocessing import StandardScaler
sc=StandardScaler()
patient[['Age','Weight','Glucose_t-3','Glucose_t-2','Glucose_t-1','Carb_t-1','Insulin_t-
1','Glucose_t-4']] = sc.fit_transform(patient[['Age','Weight','Glucose_t-3','Glucose_t-2','Glucose_t-
1','Carb_t-1','Insulin_t-1','Glucose_t-4']])
data = patient.iloc[:,0:9]
然后之后我尝试使用以下代码转换测试数据
test_data = sc.transform(test)
上面的行给出了错误。当我打印两个数组测试的形状和它给出的数据时,
print(test.shape)
print(data.shape)
(114, 9) ------ test shape
(2206, 9) ----- data shape
列是相同的,只是记录的数量不同。我究竟做错了什么?
解决方案
这是因为您适合在 8 列上转换数据 - 而不是 9 列。您缺少列名。
- '年龄',
- '重量',
- '葡萄糖_t-3',
- '葡萄糖_t-2',
- '葡萄糖_t- 1',
- 'Carb_t-1',
- '胰岛素_t-1',
- '葡萄糖_t-4'
推荐阅读
- java - 如果返回类型为 java.sql.Timestamp,则基于接口的投影 getter 方法会给出异常
- javascript - 按钮未单击我使用了 javascript 和 Actions 语法
- java - java GMT datetimeparse
- ruby-on-rails - Rails 4:JSON::GeneratorError:JSON 中不允许 NaN
- git - 我可以让 Git 在不实际提取提交数据的情况下获取存储库标记列表吗?
- javascript - 是否有可能从 JavaScript 中的嵌套处理程序方法访问类方法?
- c# - 使用 Enter 键更改用户控件中文本框的焦点
- string - 严格将字符串转换为 int
- python - 无法使用附加构造约束(scipy.optimize.minimize)
- entity-framework - .NET Core WebApp,多个域,根据主机名更改 SQL 连接字符串,无法将 httpcontext 注入 DB Context.cs 文件