【发布时间】:2020-09-22 08:50:39
【问题描述】:
我正在使用XGBRegressor 来拟合使用gridsearchcv 的模型。我想对树木进行可视化。
这是我关注的链接(如果重复)how to plot a decision tree from gridsearchcv?
xgb = XGBRegressor(learning_rate=0.02, n_estimators=600,silent=True, nthread=1)
folds = 5
grid = GridSearchCV(estimator=xgb, param_grid=params, scoring='neg_mean_squared_error', n_jobs=4, verbose=3 )
model=grid.fit(X_train, y_train)
方法一:
dot_data = tree.export_graphviz(model.best_estimator_, out_file=None,
filled=True, rounded=True, feature_names=X_train.columns)
dot_data
Error: NotFittedError: This XGBRegressor instance is not fitted yet. Call 'fit' with appropriate arguments before using this estimator.
方法二:
tree.export_graphviz(best_clf, out_file='tree.dot',feature_names=X_train.columns,leaves_parallel=True)
subprocess.call(['dot', '-Tpdf', 'tree.dot', '-o' 'tree.pdf'])
同样的错误。
【问题讨论】:
标签: python plot scikit-learn decision-tree xgboost