How To Get Predictions For Each Set Of Parameters Using Gridsearchcv?
I'm trying to find the best parameters for NN regression model using GridSearchCV with following code: param_grid = dict(optimizer=optimizer, epochs=epochs, batch_size=batches, i
Solution 1:
You can replace standard 3-folds cv parameter of GridSearchCV
with custom iterator, which yields train and test indices of concatenated train and test dataframes. In result, while 1-fold cross validation you'l train your model on input_train
objects and test your fitted model on input_test
objects:
def modified_cv(input_train_len, input_test_len):
yield (np.array(range(input_train_len)),
np.array(range(input_train_len, input_train_len + input_test_len)))
input_train_len = len(input_train)
input_test_len = len(input_test)
data = np.concatenate((input_train, input_test), axis=0)
target = np.concatenate((target_train, target_test), axis=0)
grid = GridSearchCV(estimator=model,
param_grid=param_grid,
cv=modified_cv(input_train_len, input_test_len),
scoring='neg_mean_squared_error')
grid_result = grid.fit(data, target)
By accessing grid_result.cv_results_
dictionary, you'l see your metrics value on test set for all grid of specified model parameters.
Post a Comment for "How To Get Predictions For Each Set Of Parameters Using Gridsearchcv?"