【问题标题】:Value Error: operands could not be broadcast together with shapes (114,9) (8,) (114,9)值错误:操作数无法与形状一起广播 (114,9) (8,) (114,9)
【发布时间】:2020-04-08 14:51:51
【问题描述】:

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

上面的行给出了错误。当我打印两个数组 test 的形状和它给出的数据时,

print(test.shape)
print(data.shape)


(114, 9) ------ test shape
(2206, 9) ----- data shape

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

【问题讨论】:

    标签: python machine-learning


    【解决方案1】:

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

    1. “年龄”,
    2. '重量',
    3. 'Glucose_t-3',
    4. 'Glucose_t-2',
    5. '葡萄糖_t-1',
    6. 'Carb_t-1',
    7. 'Insulin_t-1',
    8. 'Glucose_t-4'

    【讨论】:

    • 非常感谢。你的解释确实有效。再次感谢
    猜你喜欢
    • 2018-02-28
    • 2019-09-01
    • 1970-01-01
    • 2022-09-24
    • 2015-05-18
    • 2017-09-09
    • 2020-09-06
    • 2012-10-31
    • 2013-04-07
    相关资源
    最近更新 更多