imblearn 管道中的类型错误:类型“管道”不可下标

问题描述 投票:0回答:1
transform = [("ord", OrdinalEncoder(), ['job', 'education']),
             ("ohe", OneHotEncoder(), ['contact', 'month', 'poutcome'])]

ct = ColumnTransformer(transform, remainder='passthrough')

p = imbpipeline[('ct', ct),
                ('scaler', StandardScaler()),
                ('smote', SMOTE(random_state=0)),
                ('xgb', XGBClassifier())]

尝试运行上述内容时出现错误

"TypeError: type 'Pipeline' is not subscriptable"
python pandas machine-learning imblearn
1个回答
0
投票

由于实例化时列表周围缺少圆括号,您会收到 TypeError

imbpipeline
:

p = imbpipeline([('ct', ct),
                ('scaler', StandardScaler()),
                ('smote', SMOTE(random_state=0)),
                ('xgb', XGBClassifier())
])

术语“可下标”是指可以迭代的对象,例如

list
dict
。方括号用于切片,例如
a[0]
。并且
imbpipeline
无法在方括号内的位置访问。这就是您收到错误的原因。

© www.soinside.com 2019 - 2024. All rights reserved.