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"
由于实例化时列表周围缺少圆括号,您会收到 TypeError
imbpipeline
:
p = imbpipeline([('ct', ct),
('scaler', StandardScaler()),
('smote', SMOTE(random_state=0)),
('xgb', XGBClassifier())
])
术语“可下标”是指可以迭代的对象,例如
list
或 dict
。方括号用于切片,例如a[0]
。并且imbpipeline
无法在方括号内的位置访问。这就是您收到错误的原因。