Python中的DecisonTreeclassifer()-尝试构建树时出错
我正在使用以下代码构建决策树。获得最佳条件后,使用gridsearch构建树。当我使用graphviz绘制树时,我得到了以下错误Python中的DecisonTreeclassifer()-尝试构建树时出错,python,machine-learning,scikit-learn,Python,Machine Learning,Scikit Learn,我正在使用以下代码构建决策树。获得最佳条件后,使用gridsearch构建树。当我使用graphviz绘制树时,我得到了以下错误 Error--- File "C:\Users\lalitha.sundar\AppData\Local\Continuum\anaconda3\lib\site-packages\sklearn\tree\export.py", line 396, in export_graphviz check_is_fitted(decision_tree, 'tr
Error---
File "C:\Users\lalitha.sundar\AppData\Local\Continuum\anaconda3\lib\site-packages\sklearn\tree\export.py", line 396, in export_graphviz
check_is_fitted(decision_tree, 'tree_')
File "C:\Users\lalitha.sundar\AppData\Local\Continuum\anaconda3\lib\site-packages\sklearn\utils\validation.py", line 951, in check_is_fitted
raise NotFittedError(msg % {'name': type(estimator).__name__})
NotFittedError: This RandomizedSearchCV instance is not fitted yet. Call 'fit' with appropriate arguments before using this method.
您需要调用
clf\u fit.best\u estimator\u
以获得具有最佳CV分数的最佳估计器。这将是已安装的DecisionTreeClassifier
的一个实例
export_graphviz(clf_fit.best_estimator_, out_file=dot_data,
filled=True, rounded=True,
special_characters=True, feature_names = feature_cols,class_names=['0','1'])
谢谢拉兹米克。我不熟悉用python运行决策树。你能帮我编辑代码吗?或者我应该把代码添加到哪里_
export_graphviz(clf_fit.best_estimator_, out_file=dot_data,
filled=True, rounded=True,
special_characters=True, feature_names = feature_cols,class_names=['0','1'])