我正在构建一个用于预测二进制目标变量的ML模型。当构建随机森林时,我想运行GridSearchCV()以便能够交叉验证我的结果。我已经导入了所有必要的库。它给了我错误:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
/var/folders/6s/sjprd_n541b06ly63j2zcbg40000gn/T/ipykernel_15789/3909671296.py in <module>
9
10 start=time.time()
---> 11 rfc_grid_search = GridSearchCV(param_grid, cv=10,
12 scoring='f1_macro',
13 return_train_score=True,njobs=-1)
TypeError: __init__() got an unexpected keyword argument 'njobs'
#random forest
param_grid = [
{
'rfc__n_estimators': [100, 200, 500],
'rfc__max_depth': [5, None]
},
]
start=time.time()
rfc_grid_search = GridSearchCV(param_grid, cv=10,
scoring='f1_macro',
return_train_score=True,njobs=-1)
rfc_grid_search.fit(X_train, Y_train)
end = (time.time() - start)/3600
print(f"Took {end} hours")
我想你用的是sklearn.model_selection.GridSearchCV
中的GrideSearchCV
。
如果是这样,你应该用n_jobs
而不是njobs
。