Search code examples
pythonpandasscikit-learndecision-treegridsearchcv

Optimize hyper-parameters of a decision tree


I am trying to use to sklearn grid search to find the optimal parameters for the decision tree.

Dtree= DecisionTreeRegressor()
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() 

Solution

  • Maybe this?

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