You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在PyCaret的tune_model中设置n_jobs启用多进程调参?

解决PyCaret调参时n_jobs参数冲突的问题

错误原因

你遇到的TypeError: ABCMeta object got multiple values for keyword argument 'n_jobs',是因为PyCaret的tune_model函数在内部已经会向底层的RandomizedSearchCV传递n_jobs参数(默认值通常为1),当你额外通过**kwargs传递该参数时,会导致同一个参数被重复传入,触发冲突。


解决方案

根据你使用的PyCaret版本,分两种方式处理:

1. 使用PyCaret v3及以上版本

PyCaret v3的tune_model已经内置了n_jobs参数,直接指定即可启用多进程,无需通过**kwargs传递:

from pycaret.classification import setup, tune_model

# 初始化分类任务环境
setup(data=你的数据集, target='目标列名')

# 直接设置n_jobs=-1,启用全部可用进程
tuned_model = tune_model(estimator=你的模型实例, n_jobs=-1)

2. 使用PyCaret v2及以下版本

旧版本tune_model未内置n_jobs参数,需自定义RandomizedSearchCV实例,通过search_estimator参数传入,避免参数冲突:

from pycaret.classification import setup, tune_model
from sklearn.model_selection import RandomizedSearchCV
from sklearn.ensemble import RandomForestClassifier  # 替换为你实际使用的模型

# 初始化分类任务环境
setup(data=你的数据集, target='目标列名')

# 定义超参数搜索网格(根据你的模型调整)
param_grid = {
    'n_estimators': [50, 100, 200],
    'max_depth': [None, 10, 20],
    'min_samples_split': [2, 5]
}

# 创建自定义调参器,设置n_jobs=-1启用全进程
custom_tuner = RandomizedSearchCV(
    estimator=RandomForestClassifier(),
    param_distributions=param_grid,
    n_iter=20,
    cv=5,
    n_jobs=-1,
    random_state=42
)

# 传入自定义调参器执行调参
tuned_model = tune_model(estimator=RandomForestClassifier(), search_estimator=custom_tuner)

内容的提问来源于stack exchange,提问作者Carl C

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.12 19:52:07