值错误:操作数不能与形状(114,9)(8,)(114,9)一起广播

问题描述 投票:0回答:1

我正在尝试使用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

这些列是相同的,只是记录的数量不同。我在做什么错?

python machine-learning
1个回答
0
投票

这是因为您适合将数据转换为8列,而不是9列。您缺少列名。

  1. '年龄',
  2. '体重',
  3. 'Glucose_t-3',
  4. 'Glucose_t-2',
  5. 'Glucose_t-1',
  6. 'Carb_t-1',
  7. 'Insulin_t-1',
  8. 'Glucose_t-4'
© www.soinside.com 2019 - 2024. All rights reserved.