Python 错误:";管道的最后一步应该实现fit,或者是字符串';直通';
我已经创建了一个管道,该管道应该适合我的数据和评分本身的不同模型,但我收到了这个错误 代码如下:Python 错误:";管道的最后一步应该实现fit,或者是字符串';直通';,python,Python,我已经创建了一个管道,该管道应该适合我的数据和评分本身的不同模型,但我收到了这个错误 代码如下: `models = {"Ridge": Ridge(), "SVR_linear": SVR(kernel="linear"), "SVR_rbf": SVR(kernel="rbf"), "RandomForestRegres
`models = {"Ridge": Ridge(),
"SVR_linear": SVR(kernel="linear"),
"SVR_rbf": SVR(kernel="rbf"),
"RandomForestRegressor": RandomForestRegressor()}
reg_results = {}`
`for model_name, model in models.items():
# Model preprocessor with pipeline
model_pipeline = Pipeline(steps=[("preprocessor", preprocessor),
("model", models)])
# Fit models
print(f"Fitting {model_name}...")
model_pipeline.fit(car_X_train, car_y_train)
# Score model and append model results dict with values
print(f"Scoring {model_name}...")
reg_results[model_name] = model.pipeline.score(car_X_test, car_y_test)`
将“模型”替换为“模型”
- 因为“模型”是你的模型字典
- 您应该在这个管道步骤中使用字典值(来自for循环的“model”)
模型
分配给您的管道,而不是模型
。谢谢,这很有效。
model_pipeline = Pipeline(steps=[("preprocessor", preprocessor),
("model", model)])