ikit学习在DecisionTreeClassifier上使用

ikit学习在DecisionTreeClassifier上使用

本文介绍了Scikit学习在DecisionTreeClassifier上使用GridSearchCV的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在DecisionTreeClassifier上使用GridSearchCV,但出现以下错误:TypeError:必须以DecisionTreeClassifier实例作为第一个参数来调用未绑定方法get_params()(而是什么也不做)

I tried to use GridSearchCV on DecisionTreeClassifier, but get the following error:TypeError: unbound method get_params() must be called with DecisionTreeClassifier instance as first argument (got nothing instead)

这是我的代码:

from sklearn.tree import DecisionTreeClassifier, export_graphviz
from sklearn.grid_search import GridSearchCV
from sklearn.cross_validation import  cross_val_score

X, Y = createDataSet(filename)
tree_para = {'criterion':['gini','entropy'],'max_depth':[4,5,6,7,8,9,10,11,12,15,20,30,40,50,70,90,120,150]}
clf = GridSearchCV(DecisionTreeClassifier, tree_para, cv=5)
clf.fit(X, Y)

推荐答案

在调用GridSearchCV方法时,第一个参数应该是DecisionTreeClassifier的实例化对象,而不是类的名称.应该是

In your call to GridSearchCV method, the first argument should be an instantiated object of the DecisionTreeClassifier instead of the name of the class. It should be

clf = GridSearchCV(DecisionTreeClassifier(), tree_para, cv=5)

请查看示例此处了解更多详细信息

Check out the example here for more details.

希望有帮助!

这篇关于Scikit学习在DecisionTreeClassifier上使用GridSearchCV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 18:58