Questions tagged [grid-search]

In machine learning, grid search refers to multiple runs to find the optimal value of parameter(s)/hyperparameter(s) of a model, e.g. mtry for random-forest or alpha, beta, lambda for glm, or C, kernel and gamma for SVM.

865 questions
22
votes
2 answers

AttributeError: 'GridSearchCV' object has no attribute 'best_params_'

Grid search is a way to find the best parameters for any model out of the combinations we specify. I have formed a grid search on my model in the below manner and wish to find best parameters identified using this gridsearch. from…
noob
  • 3,601
  • 6
  • 27
  • 73
21
votes
2 answers

scikit-learn GridSearchCV with multiple repetitions

I'm trying to get the best set of parameters for an SVR model. I'd like to use the GridSearchCV over different values of C. However, from the previous test, I noticed that the split into the Training/Test set highly influences the overall…
Titus Pullo
  • 3,751
  • 15
  • 45
  • 65
21
votes
3 answers

Is there a quicker way of running GridsearchCV

I'm optimizing some paramters for an SVC in sklearn, and the biggest issue here is having to wait 30 minutes before I try out any other parameter ranges. Worse is the fact that I'd like to try more values for c and gamma within the same range (so I…
bidby
  • 708
  • 1
  • 10
  • 24
20
votes
2 answers

Skip forbidden parameter combinations when using GridSearchCV

I want to greedily search the entire parameter space of my support vector classifier using GridSearchCV. However, some combinations of parameters are forbidden by LinearSVC and throw an exception. In particular, there are mutually exclusive…
crypdick
  • 16,152
  • 7
  • 51
  • 74
20
votes
2 answers

How to use GridSearchCV output for a scikit prediction?

In the following code: # Load dataset iris = datasets.load_iris() X, y = iris.data, iris.target rf_feature_imp = RandomForestClassifier(100) feat_selection = SelectFromModel(rf_feature_imp, threshold=0.5) clf = RandomForestClassifier(5000) model…
user308827
  • 21,227
  • 87
  • 254
  • 417
19
votes
3 answers

Pipeline: Multiple classifiers?

I read following example on Pipelines and GridSearchCV in Python: http://www.davidsbatista.net/blog/2017/04/01/document_classification/ Logistic Regression: pipeline = Pipeline([ ('tfidf', TfidfVectorizer(stop_words=stop_words)), ('clf',…
Christopher
  • 2,120
  • 7
  • 31
  • 58
18
votes
1 answer

More than one estimator in GridSearchCV(sklearn)

I was checking sklearn documentation webpage about GridSearchCV. One of attributes of GridSearchCV object is best_estimator_. So here is my question. How to pass more than one estimator to GSCV object? Using a dictionary like: {'SVC()':{'C':10,…
mikinoqwert
  • 375
  • 3
  • 15
18
votes
2 answers

Avoid certain parameter combinations in GridSearchCV

I'm using scikit-learn's GridSearchCV to iterate over a parameter space to tune a model. Specifically, I'm using it to test different hyperparameters in a neural network. The grid is as follows: params = {'num_hidden_layers': [0,1,2], …
17
votes
3 answers

Get feature importance from GridSearchCV

Is there a way to get feature importance from a sklearn's GridSearchCV? For example : from sklearn.model_selection import GridSearchCV print("starting grid search ......") optimized_GBM = GridSearchCV(LGBMRegressor(), …
Nick M
  • 822
  • 1
  • 7
  • 20
17
votes
3 answers

Grid Search and Early Stopping Using Cross Validation with XGBoost in SciKit-Learn

I am fairly new to sci-kit learn and have been trying to hyper-paramater tune XGBoost. My aim is to use early stopping and grid search to tune the model parameters and use early stopping to control the number of trees and avoid overfitting. As I am…
George
  • 674
  • 2
  • 7
  • 19
16
votes
3 answers

How to perform feature selection with gridsearchcv in sklearn in python

I am using recursive feature elimination with cross validation (rfecv) as a feature selector for randomforest classifier as follows. X = df[[my_features]] #all my features y = df['gold_standard'] #labels clf = RandomForestClassifier(random_state =…
EmJ
  • 4,398
  • 9
  • 44
  • 105
16
votes
3 answers

How to save GridSearchCV object?

Lately, I have been working on applying grid search cross validation (sklearn GridSearchCV) for hyper-parameter tuning in Keras with Tensorflow backend. An soon as my model is tuned I am trying to save the GridSearchCV object for later use without…
E.Thrampoulidis
  • 179
  • 1
  • 1
  • 5
16
votes
3 answers

Explicitly specifying test/train sets in GridSearchCV

I have a question about the cv parameter of sklearn's GridSearchCV. I'm working with data that has a time component to it, so I don't think random shuffling within KFold cross-validation seems sensible. Instead, I want to explicitly specify cutoffs…
Brad Solomon
  • 38,521
  • 31
  • 149
  • 235
16
votes
2 answers

Cross validation with grid search returns worse results than default

I'm using scikitlearn in Python to run some basic machine learning models. Using the built in GridSearchCV() function, I determined the "best" parameters for different techniques, yet many of these perform worse than the defaults. I include the…
16
votes
3 answers

Keras: Out of memory when doing hyper parameter grid search

I'm running multiple nested loops to do hyper parameter grid search. Each nested loop runs through a list of hyper parameter values and inside the innermost loop, a Keras sequential model is built and evaluated each time using a generator. (I'm not…
Alex
  • 3,316
  • 4
  • 26
  • 52
1
2
3
57 58