13 votes
Accepted

Parameters in GridSearchCV in scikit-learn

Well the error message is quite clear. GridSearchCV accepts only lists. Therefore 'random_state': [7]} will solve the issue. However when you have only one value ...
  • 1,671
11 votes
Accepted

What is GridSearchCV doing after it finishes evaluating the performance of parameter combinations that takes so long?

Yep I figured it out. The answer is that by default GridSearchCV's last act is to expose the API of the estimator object you passed so that you can directly call things like ...
  • 1,714
9 votes

Why GridSearchCV returns nan?

By default, GridSearchCV provides a score of nan when fitting the model fails. You can change that behavior and raise an error ...
  • 10.6k
6 votes

Parameters in GridSearchCV in scikit-learn

I would say that you have to remove random_state from the parameter grid. That, or put something like [7, X] which will work but that doesn't make sense I think. If ...
  • 1,160
4 votes

How to implement gridsearchCV for onevsrestclassifier of LogisticRegression classifier?

When you use nested estimators with grid search you can scope the parameters with __ as a separator. In this case the LogisticRegression model is stored as an attribute named estimator inside the ...
  • 41
4 votes
Accepted

How is the GridsearchCV Score calculated?

The score is based on the scorer defined in the scoring argument. Meaning, the scorer can be any of the default metrics, such as precision, accuracy or F1-score (e.g., this); or a custom scorer. For a ...
  • 172
3 votes
Accepted

sklearn.model_selection: GridSearchCV vs. KFold

Yes, you can replace the cv=5 with cv=KFold(n_splits=5, random_state=None, shuffle=False). Leaving it set to an integer, like 5, ...
  • 1,714
3 votes
Accepted

How to cache GridSearchCV optimizer result in Google Colab?

We can save the trained model or any other file via Google Colaboratory. How I'm using it? I have mapped my Google Drive with Google Colaboratory notebook and saved trained model as a pickle ...
  • 1,234
3 votes

Large negative R2 or accuracy scores for random forest with GridSearchCV but not train_test_split

Negative R2 values can be observed when using it in the context of model validation (where we have data that is withheld from the model) because in this context, SST $\ne$ SSE + SSR. That is, this ...
  • 1,864
3 votes

Large negative R2 or accuracy scores for random forest with GridSearchCV but not train_test_split

R2 can be negative if the model is arbitrarily worse according to the sklearn documentation So the very negative train scores were indicative of an extremely bad performance. Why was the test ...
  • 151
3 votes
Accepted

How to get mean test scores from GridSearchCV with multiple scorers - scikit-learn

For multi-metric evaluation, the scores for all the scorers are available in the cv_results_ dict at the keys ending with that scorer's name ('_scorer_name'). so use grid.cv_results_['mean_test_(...
  • 526
3 votes

Default parameters for decision trees give better results than parameters optimised using GridsearchCV

My Suggestion: The intrinsic separation of classes needs more complex model to be captured. I say this, because the difference between default model and your grid search is in max_depth parameter ...
3 votes
Accepted

How to combine GridSearchCV with Early Stopping?

Just to add to others here. I guess you simply need to include a early stopping callback in your fit(). Something like: ...
  • 7,124
3 votes

Is it alright to split a GridSearchCV?

First my understanding of your problem. You want to find the best hyperparameters for a Random Forest. For that, you want to first adjust n_estimators parameter and then the rest of parameters in ...
3 votes
Accepted

Feature Importance from GridSearchCV

I think that you just need: feature_importances = rf_gridsearch.best_estimator_.feature_importances_ This provides the feature importance for all the attributes in ...
3 votes

When using GridSearchCV with regression tree how to interpret mean_test_score?

By default, GridSearchCV uses the score method of its estimator; see the last paragraph of the ...
  • 10.6k
2 votes

Sklearn Pipelines - How to carry over PCA?

When doing GridSearchCv, the best model is already scored. You can access it with the attribute best_score_ and get the model with ...
  • 1,071
2 votes
Accepted

How to set class-weight for imbalanced classes in KerasClassifier while it is used inside the GridSearchCV?

grid_result = grid.fit(X_train, y_train, clf__class_weight={0:0.95, 1:0.05}) FYI, per the docs fit_params should no longer be ...
2 votes

sklearn.GridSearchCV predict method not providing the best estimate and accuracy score

Summarizing your results - your trained a model using gridsearch. accuracy score on the train set is ~0.78. accuracy score on the test set is ~0.59. Rephrasing you questions: why do my model ...
  • 983
2 votes

How to implement gridsearchCV for onevsrestclassifier of LogisticRegression classifier?

You can see I have set up a basic pipeline here using GridSearchCV, tf-idf, Logistic Regression and OneVsRestClassifier. In the param_grid, you can set ...
2 votes

GridSearchCV with MLPRegressor with Scikit learn

It would be helpful to get the ouput of the program (or at least the error thrown) However, MLPRegressor hidden_layer_sizes is a tuple, please change it to: ...
2 votes

XGBOOST (sklearn interface) REGRESSION error

Upgrade your xgboost version. reg:squarederror was added in 0.83 release (In version 0.82 or below, use reg:linear) In general,...
  • 331
2 votes

How to print accuracy in each fold of Validation Dataset? and assign fold number to each row in the dataframe?

You're mixing up GridSearchCV and cross_val_score; you should only need to run one of them. ...
  • 10.6k
2 votes
Accepted

How to choose the model parameters (RandomizedSearchCV, .GridSearchCV) or manually

Thanks for the clarification. You can configure the parameters once or twice at a time by re-instantiating the RSCV object each time, passing different parameter dictionaries each time. For example: <...
  • 1,714
2 votes
Accepted

CNNs - Hyperparameter tuning with different training sizes of the same data set

First suggestion: you should first find a CNN architecture that satisfies you, and then stick with it. Second suggestion: be careful with cross validation. CNNs are extremely "heavy" models, they can ...
  • 5,797
2 votes

How to combine GridSearchCV with Early Stopping?

If you would ask for code suggestion please specify your framework in the future. I am assuming you are using Keras I can make you a minimum viable implementation of your case. ...
2 votes

How to plot number of Trees and OOBs score with Grid Search

To plot feature importance using gridsearch use: x= X_train_v1.columns,y= rf_grid_search_v1.best_estimator_.feature_importances_
2 votes
Accepted

Why does my GridSearchCV always break up?

First, you are fitting $5 \cdot 3\cdot2\cdot2\cdot2\cdot5=600$ models and n_estimator=500 is quite big. Of course, this depends on your dataset and in your computing power. My first guess will be ...
2 votes

Is it alright to split a GridSearchCV?

Edit: oh, now I think I see why @CarlosMougan said no. You said ...start the same GridsearchCV with the same parameter and just change... If you mean use the optimal values for all ...
  • 10.6k
2 votes

How many trees does a Random Forest need?

By other posts and this one seems what you don't have a clear intuition of the n_estimators of the random forest. I am going to assume that you are referring to the n_estimators (from this other ...

Only top scored, non community-wiki answers of a minimum length are eligible