优化决策树的超参数

时间:2020-02-21 14:17:50

标签: python pandas scikit-learn decision-tree gridsearchcv

我正在尝试使用sklearn网格搜索来找到决策树的最佳参数。

   parameter_space = {'max_features': ['auto', 'sqrt', 'log2'],
                     'ccp_alpha': [np.array(pd.Series(np.arange(0,1,0.001)))]}

   clf_tree = GridSearchCV(Dtree, parameter_space,cv=5)
   clf=clf_tree.fit(X,y)

I got the following error. I was wondering if you could help me to resolve this. I appreciate your time. 

    ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all() 

1 个答案:

答案 0 :(得分:1)

也许是吗?

parameter_space = {'max_features': ['auto', 'sqrt', 'log2'], 'ccp_alpha': np.arange(0, 1, 0.001).tolist()}