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
11
votes
1 answer

Is there a way to see the folds for cross-validation in GridSearchCV?

I'm currently doing a 3-fold cv using GridSearchCV in Python to optimize hyperparameters. I'm just wondering if there is any way to see the indices of training and testing data in the cv used in GridSearchCV?
Frederica
  • 187
  • 1
  • 7
11
votes
1 answer

Random search without cross validation in python/sklearn

If you want to do grid search in sklearn without cross validation (what GridSearchCV does), you can apparently use the ParameterGrid class (see here: Is there easy way to grid search without cross validation in python?). Does anyone know of a…
jrieke
  • 975
  • 10
  • 15
11
votes
4 answers

GridSearchCV: "TypeError: 'StratifiedKFold' object is not iterable"

I want to perform GridSearchCV in a RandomForestClassifier, but data is not balanced, so I use StratifiedKFold: from sklearn.model_selection import StratifiedKFold from sklearn.grid_search import GridSearchCV from sklearn.ensemble import…
user183897
  • 111
  • 1
  • 1
  • 4
10
votes
2 answers

RandomForestRegressor and feature_importances_ error

I am struggling to pull out the feature importances from my RandomForestRegressor, I get an: AttributeError: 'GridSearchCV' object has no attribute 'feature_importances_'. Anyone know why there is no attribute? According to documentation there…
10
votes
1 answer

Hyperas grid search with a network with multiple inputs

I currently having problems using hyperas optimiser on my network with multiple inputs.. This is how I've implemented it: def data(): X_train, Y_train = next(train_generator()) X_test, Y_test = next(test_generator()) datagen =…
J.Down
  • 700
  • 1
  • 9
  • 32
9
votes
1 answer

GridSearch for best model: Save and load parameters

I like to run following workflow: Selecting a model for text vectorization Defining a list of parameters Applying a pipeline with GridSearchCV on the parameters, using LogisticRegression() as a baseline to find the best model parameters Save the…
Christopher
  • 2,120
  • 7
  • 31
  • 58
9
votes
0 answers

What is the training complexity of Sklearn GridSearch?

gs_clf = GridSearchCV(SVC(probability=False, class_weight='balanced', max_iter=100, random_state=2018, tol=1e-10), param_grid={'C': [2, 5, 10] , 'kernel': 'linear'}, n_jobs=1, …
Richie F.
  • 104
  • 1
  • 9
9
votes
1 answer

Loss, metrics, and scoring in Keras

What is the difference between loss, metrics and scoring in building a keras model? Should they be different or same? In a typical model, we use all of the three forGridSearchCV. Here is the snapshot of a typical model for regression which uses all…
Stupid420
  • 1,347
  • 3
  • 19
  • 44
9
votes
1 answer

XGBoost with GridSearchCV, Scaling, PCA, and Early-Stopping in sklearn Pipeline

I want to combine a XGBoost model with input scaling and feature space reduction by PCA. In addition, the hyperparameters of the model as well as the number of components used in the PCA should be tuned using cross-validation. And to prevent the…
winwin
  • 384
  • 6
  • 20
9
votes
2 answers

Interpreting sklearns' GridSearchCV best score

I would like to know the difference between the score returned by GridSearchCV and the R2 metric calculated as below. In other cases I receive the grid search score highly negative (same applies for cross_val_score) and I would be grateful for…
abu
  • 737
  • 5
  • 8
  • 19
9
votes
1 answer

GridSearchCV - save result each iteration

I'm using GridSearchCV, and after each iteration I want to save the clf.cv_results_ property to a file, (just in case that the process will crash in the middle). I tried looking for a solution but I just couldn't figure it out. Any help will be…
9
votes
2 answers

Grid Search parameter and cross-validated data set in KNN classifier in Scikit-learn

I'm trying to perform my first KNN Classifier using SciKit-Learn. I've been following the User Guide and other online examples but there are a few things I am unsure about. For this post lets use the following X = data Y = target In most…
browser
  • 313
  • 1
  • 3
  • 12
9
votes
1 answer

Random Forest hyperparameter tuning scikit-learn using GridSearchCV

I am trying to use Random forest for my problem (below is a sample code for boston datasets, not for my data). I am planning to use GridSearchCV for hyperparameter tuning but what should be the range of values for different parameters? How will I…
Muhammad
  • 305
  • 2
  • 6
  • 20
9
votes
1 answer

Scikit - Combining scale and grid search

I am new to scikit, and have 2 slight issues to combine a data scale and grid search. Efficient scaler Considering a cross validation using Kfolds, I would like that each time we train the model on the K-1 folds, the data scaler (using…
cpeusteuche
  • 339
  • 1
  • 3
  • 11
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…