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.
Questions tagged [grid-search]
865 questions
16
votes
5 answers
Scikit-learn using GridSearchCV on DecisionTreeClassifier
I tried to use GridSearchCV on DecisionTreeClassifier, but get the following error:
TypeError: unbound method get_params() must be called with DecisionTreeClassifier instance as first argument (got nothing instead)
here's my code:
from sklearn.tree…

user5425156
- 387
- 1
- 4
- 8
15
votes
0 answers
Nested cross-validation example on Scikit-learn
I'm trying to work my head around the example of Nested vs. Non-Nested CV in Sklearn. I checked multiple answers but I am still confused on the example.
To my knowledge, a nested CV aims to use a different subset of data to select the best…

NCL
- 355
- 2
- 4
- 12
15
votes
1 answer
Do I need to split data when using GridSearchCV?
Gridsearhcv uses StratifiedKFold or KFold. So my question is that should I split my data into train and test before using gridsearch, then do fitting only for test data? I am not sure whether it is necessary because cv method already splits the data…

Kübra Kutlu
- 163
- 1
- 1
- 7
15
votes
1 answer
How to estimate the progress of a GridSearchCV from verbose output in Scikit-Learn?
Right now I'm running a pretty aggressive grid search. I have n=135 samples and I am running 23 folds using a custom cross-validation train/test list. I have my verbose=2.
The following is what I ran:
param_test = {"loss":["deviance"],
…

O.rka
- 29,847
- 68
- 194
- 309
14
votes
2 answers
Is there a way to perform grid search hyper-parameter optimization on One-Class SVM
Is there a way to use GridSearchCV or any other built-in sklearn function to find the best hyper-parameters for OneClassSVM classifier?
What I currently do, is perform the search myself using train/test split like this:
Gamma and nu values are…

Yustx
- 326
- 1
- 4
- 12
13
votes
2 answers
how to tune parameters of custom kernel function with pipeline in scikit-learn
currently I have successfully defined a custom kernel function(pre-computing the kernel matrix) using def function, and now I am using the GridSearchCV function to get the best parameters.
so, in the custom kernel function, there is a total of 2…

ZAWD
- 651
- 7
- 31
12
votes
1 answer
what is Gridsearch.cv_results_ , could any explain all the things in that i.e mean_test_score etc .?
I am doing hyperparameter tuning with GridSearchCV for Decision Trees. I have fit the model and I am trying to find what does exactly Gridsearch.cv_results_ gives. I have read the documentation but still its not clear. Could anyone explain this…

Vishal Suryavanshi
- 355
- 1
- 4
- 15
12
votes
2 answers
Alternate different models in Pipeline for GridSearchCV
I want to build a Pipeline in sklearn and test different models using GridSearchCV.
Just an example (please do not pay attention on what particular models are chosen):
reg = LogisticRegression()
proj1 = PCA(n_components=2)
proj2 = MDS()
proj3 =…

sooobus
- 841
- 1
- 9
- 22
12
votes
2 answers
GridSearchCV Random Forest Regressor Tuning Best Params
I want to improve the parameters of this GridSearchCV for a Random Forest Regressor.
def Grid_Search_CV_RFR(X_train, y_train):
from sklearn.model_selection import GridSearchCV
from sklearn.model_selection import ShuffleSplit
from…

ambigus9
- 1,417
- 3
- 19
- 37
12
votes
0 answers
SARIMAX model fitting too slow in statsmodels
I am trying a grid search to perform model selection by fitting SARIMAX(p, d, q)x(P, D, Q, s) models using SARIMAX() method in statsmodels. I do set d and D to 1 and s to 7 and iterate over values of p in {0, 1}, q in {0, 1, 2}, P in {0, 1}, Q in…

darXider
- 447
- 5
- 16
12
votes
4 answers
Grid-Search finding Parameters for AUC
I'm trying to find the parameters for my SVM, which give me the best AUC. But i can't find any scoring function for AUC in sklearn. Does someone have an idea? Here is my Code:
parameters = {"C":[0.1, 1, 10, 100, 1000], "gamma":[0.1, 0.01, 0.001,…

julianspaeth
- 205
- 1
- 3
- 9
11
votes
2 answers
Grid search with LightGBM example
I am trying to find the best parameters for a lightgbm model using GridSearchCV from sklearn.model_selection. I have not been able to find a solution that actually works.
I have managed to set up a partly working code:
import numpy as np
import…

bhaskarc
- 9,269
- 10
- 65
- 86
11
votes
2 answers
How to implement SMOTE in cross validation and GridSearchCV
I'm relatively new to Python. Can you help me improve my implementation of SMOTE to a proper pipeline? What I want is to apply the over and under sampling on the training set of every k-fold iteration so that the model is trained on a balanced data…

MLearner
- 164
- 1
- 1
- 9
11
votes
1 answer
Why GridSearchCV in scikit-learn spawn so many threads
Here is the pstree output of my current running GridSearch, I am curious to see what processes are going on, and there is something I cannot explain yet.
├─bash─┬─perl───20*[bash───python─┬─5*[python───31*[{python}]]]
│ │ …

zyxue
- 7,904
- 5
- 48
- 74
11
votes
1 answer
Use a metric after a classifier in a Pipeline
I continue to investigate about pipeline. My aim is to execute each step of machine learning only with pipeline. It will be more flexible and easier to adapt my pipeline with an other use case. So what I do:
Step 1: Fill NaN Values
Step 2:…

Jeremie Guez
- 303
- 2
- 11