gpt4 book ai didi

python - 参数 (n_estimators) 的参数值需要是一个序列

转载 作者:太空狗 更新时间:2023-10-30 00:31:10 26 4
gpt4 key购买 nike

我遇到了错误,不知道如何解决。你能帮忙吗?完整代码可以在 https://github.com/kthouz/NYC_Green_Taxi/blob/master/NYC%20Green%20Taxi.ipynb 找到。

通过网格搜索优化 n_estimator

def optimize_num_trees(alg,param_test,scoring_method,train,predictors,target):
"""
This functions is used to tune paremeters of a predictive algorithm
alg: sklearn model,
param_test: dict, parameters to be tuned
scoring_method: str, method to be used by the cross-validation to valuate the model
train: pandas.DataFrame, training data
predictors: list, labels to be used in the model training process. They should be in the column names of dtrain
target: str, target variable
"""
gsearch = GridSearchCV(estimator=alg, param_grid = param_test, scoring=scoring_method,n_jobs=2,iid=False,cv=5)
gsearch.fit(train[predictors],train[target])
return gsearch

# get results of the search grid
gs_cls = optimize_num_trees(model_cls,param_test,'roc_auc',train,predictors,target)

---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-42-c7419a90cdb1> in <module>()
1
2 # get results of the search grid
----> 3 gs_cls = optimize_num_trees(model_cls,param_test,'roc_auc',train,predictors,target)
4

<ipython-input-40-2b76f2ffb87f> in optimize_num_trees(alg, param_test, scoring_method, train, predictors, target)
57 target: str, target variable
58 """
---> 59 gsearch = GridSearchCV(estimator=alg, param_grid = param_test, scoring=scoring_method,n_jobs=2,iid=False,cv=5)
60 gsearch.fit(train[predictors],train[target])
61 return gsearch

/Users/anaconda/lib/python3.5/site-packages/sklearn/grid_search.py in __init__(self, estimator, param_grid, scoring, fit_params, n_jobs, iid, refit, cv, verbose, pre_dispatch, error_score)
810 refit, cv, verbose, pre_dispatch, error_score)
811 self.param_grid = param_grid
--> 812 _check_param_grid(param_grid)
813
814 def fit(self, X, y=None):

/Users/anaconda/lib/python3.5/site-packages/sklearn/grid_search.py in _check_param_grid(param_grid)
346 if True not in check:
347 raise ValueError("Parameter values for parameter ({0}) need "
--> 348 "to be a sequence.".format(name))
349
350 if len(v) == 0:

ValueError: Parameter values for parameter (n_estimators) need to be a sequence.

最佳答案

我遇到了和你类似的错误:

ValueError: Parameter values for parameter (warm_start) need to be a sequence(but not a string) or np.ndarray. site:stackoverflow.com

每个键的值显然需要在数组括号 [ ] 中

我的错误代码:

params = {
'max_depth': [11],
'warm_start': True
}

我的正确代码:

params = {
'max_depth': [11],
'warm_start': [True]
}

关于python - 参数 (n_estimators) 的参数值需要是一个序列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45444953/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com