我在尝试使用spark_sklearn.GridSearchCV时,遇到了init参数错误。
TypeError: __init__() takes at least 4 arguments (4 given)
这是我的代码:
from spark_sklearn import GridSearchCVgsearch2 = GridSearchCV(estimator=ensemble.GradientBoostingRegressor(**params), param_grid=param_test2, n_jobs=1)
如果我给GridSearchCV
添加更多参数,比如添加cv=5
,那么错误会变成
TypeError: __init__() takes at least 4 arguments (5 given)
有什么建议吗?
谢谢。
回答:
GridSearchCV.__init__
需要3个必需参数:
sc
–SparkContext
。estimator
param_grid
。
你忘记了SparkContext
:
GridSearchCV( sc=SparkContext.getOrCreate(), estimator=ensemble.GradientBoostingRegressor(**params), param_grid=param_test2, n_jobs=1)