I searched to find the answer but I don´t find something with Grid Search.

I create a random forest and gradient boosting regressor with grid search. Now I want to make a visualization to see if the number of trees is alright.

# Grid-Search erstellen auf der Basis eineer Random Search 
param_grid = {
    'bootstrap': [True],
    'max_depth': [50, None],
    'max_features': ['auto', 50],
    'min_samples_leaf': [5],
    'min_samples_split': [2],
    'n_estimators': [100, 150, 200, 250, 300, 350]

# Base-Model zum Verbessern erstellen
rf_v1 = RandomForestRegressor(random_state=42)

# Grid-Search initisieren 
rf_grid_search_v1 = GridSearchCV(estimator = rf_v1, param_grid = param_grid, 
                           scoring = 'neg_mean_absolute_error', cv = 3, 
                           n_jobs = -1, verbose = 2)

# Die Grid-Search für das Model durchführen
rf_grid_search_v1.fit(X_train_v1, y_train_v1)

But how to plot the splits of trees with gridsearch? Is there any way to make an RF/xgb trees split visualization?

I am really grateful if anybody has a tip for me.

  • $\begingroup$ I want a plot with x-axis = Trees and y-axis= Error $\endgroup$
    – ml_learner
    Jan 9 '20 at 11:58
  • $\begingroup$ Your title doesn't match your question body. Do you want to plot the trees themselves, or just a simple scatter/line plot as in the title? $\endgroup$ Jan 9 '20 at 14:52
  • $\begingroup$ Plot the trees. The answers are wrong @BenReiniger (my included). $\endgroup$ Jan 9 '20 at 21:40
  • $\begingroup$ @CarlosMougan, I'm not convinced that's what OP meant (before your edit). Their comment on your answer suggests the title was the intent. But I'll wait for confirmation from them. $\endgroup$ Jan 10 '20 at 1:02
  • $\begingroup$ @BenReiniger Yes I had the same doubt than you at the beginning. When I saw the answer and the OP response to the answer I proposed changing the questions since it was not exactly clear. $\endgroup$ Jan 10 '20 at 8:19

To plot feature importance using gridsearch use:

x= X_train_v1.columns,y= rf_grid_search_v1.best_estimator_.feature_importances_
  • $\begingroup$ I understand that he refers to something like this machinelearningmastery.com/… $\endgroup$ Jan 9 '20 at 12:57
  • $\begingroup$ @CarlosMougan Thanks, Carlos. I referred to user's comment in the question section. Thus, answered with respect to plotting it using X-axis and Y-axis $\endgroup$ Jan 9 '20 at 13:20

If you want to see what is the best parameters choosen for your model you can use

  • $\begingroup$ thanks! I already did this but how do i plot this? I want a plot with x-axis = Trees and y-axis= Error $\endgroup$
    – ml_learner
    Jan 9 '20 at 11:57
  • $\begingroup$ @ml_learner I understand that you want to make something like this right ? machinelearningmastery.com/… $\endgroup$ Jan 9 '20 at 12:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.