I am using XGBRegressor
to fit the model using gridsearchcv
. I want to visulaize the trees.
Here is the link I followed ( If duplicate) 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)
Approach 1:
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.
Approach 2:
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'])
Same error.