This tag is for questions on the process of running an exhaustive search over specified parameter values for an estimator using the class GridSearchCV from Python's scikit-learn library.
Questions tagged [gridsearchcv]
597 questions
29
votes
3 answers
Memory leak using gridsearchcv
Problem: My situation appears to be a memory leak when running gridsearchcv. This happens when I run with 1 or 32 concurrent workers (n_jobs=-1). Previously I have run this loads of times with no trouble on ubuntu 16.04, but recently upgraded to…

negfrequency
- 1,801
- 3
- 18
- 30
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
16
votes
4 answers
I got the warning "UserWarning: One or more of the test scores are non-finite" when revising a toy scikit-learn gridsearchCV example
I have the following code which works normally but got a
UserWarning: One or more of the test scores are non-finite: [nan nan]
category=UserWarning
when I revised it into a more concise version (shown in the subsequent code snippet). Is the…

Li-Pin Juan
- 1,156
- 1
- 13
- 22
13
votes
3 answers
Implementing custom loss function in scikit learn
I want to implement a custom loss function in scikit learn. I use the following code snippet:
def my_custom_loss_func(y_true,y_pred):
diff3=max((abs(y_true-y_pred))*y_true)
return diff3
score=make_scorer(my_custom_loss_func,greater_…

Moonzarin Esha
- 249
- 1
- 3
- 5
11
votes
1 answer
GridSearchCV has no attribute grid.grid_scores_
tried grid.cv_results_ didnt correct problem
from sklearn.model_selection
import GridSearchCV
params = {
'decisiontreeclassifier__max_depth': [1, 2],
'pipeline-1__clf__C': [0.001, 0.1, 100.0]
}
grid = GridSearchCV(estimator = mv_clf,
…

manicsurfing
- 111
- 1
- 1
- 3
10
votes
2 answers
Result of GridSearchCV as table
I did grid search + crossvalidation on a SVM with RBF kernel to find optimal value of parameters C and gamma using the class GridShearchCV. Now I would like to get the result in a tabular format like
C/gamma 1e-3 1e-2 1e3
0.1 0.2 .. 0.3
1 …

Gianluca Amprimo
- 131
- 1
- 1
- 4
10
votes
1 answer
Using Multiple Metric Evaluation with GridSearchCV
I am attempting to use multiple metrics in GridSearchCV. My project needs multiple metrics including "accuracy" and "f1 score". However, after following the sklearn models and online posts, I can't seem to get mine to work. Here is my code:
from…

Tanner Clark
- 631
- 1
- 8
- 19
9
votes
1 answer
Where to set n_job: estimator or GridSearchCV?
I often use GridSearchCV for hyperparameter tuning. For example, for tuning regularization parameter C in Logistic Regression. Whenever an estimator I am using has its own n_jobs parameter I am confused where to set it, in estimator or in…

Aramakus
- 1,910
- 2
- 11
- 22
9
votes
2 answers
Combine GridSearchCV and StackingClassifier
I want to use StackingClassifier to combine some classifiers and then use GridSearchCV to optimize the parameters:
clf1 = RandomForestClassifier()
clf2 = LogisticRegression()
dt = DecisionTreeClassifier()
sclf = StackingClassifier(estimators=[clf1,…

xiaoluohao
- 265
- 2
- 11
9
votes
2 answers
Gridsearchcv vs Bayesian optimization
Which one among Gridsearchcv and Bayesian optimization works better for optimizing hyper parameters?

hR 312
- 824
- 1
- 9
- 22
8
votes
1 answer
How to access ColumnTransformer elements in GridSearchCV
I wanted to find out the correct naming convention when referring to individual preprocessor included in ColumnTransformer (which is part of a pipeline) in param_grid for grid_search.
Environment & sample data:
import seaborn as sns
from…

Zolzaya Luvsandorj
- 555
- 5
- 18
7
votes
0 answers
sklearn : FitFailedWarning : Estimator fit failed
As you can see, I have a problem with using sklearn (lightgbm, GridSearchCV).
Please let me know how to solve this error.
My code is the following:
import lightgbm as lgb
from lightgbm.sklearn import LGBMClassifier
estimator =…

E.Kim
- 95
- 1
- 2
7
votes
1 answer
Parameter Tuning using gridsearchcv for gradientboosting classifier in python
I am trying to run GradientBoostingClassifier() with the help of gridsearchcv.
For every combination of parameter, I also need "Precison", "recall" and accuracy in tabular format.
Here is the code:
scoring= ['accuracy',…

MAC
- 1,345
- 2
- 30
- 60
6
votes
1 answer
GridSearchCV and RandomizedSearchCV in Scikit-learn 0.24.0 or above do not print progress log with n_jobs=-1
In scikit-learn 0.24.0 or above when you use either GridSearchCV or RandomizedSearchCV and set n_jobs=-1, with setting any verbose number (1, 2, 3, or 100) no progress messages gets printed. However, if you use scikit-learn 0.23.2 or lower,…

Ashtad
- 61
- 5
6
votes
1 answer
How to properly select the best model in GridSearchCV - both sklearn and caret do it wrong
Consider 3 data sets train/val/test. sklearn's GridSearchCV() by default chooses the best model with the highest cross-validation score. In a real-world setting where the predictions need to be accurate, this is a horrible approach to choosing the…

Matt Elgazar
- 707
- 1
- 8
- 21