1

Below is my code for running KerasClassifier with a SciKit-Learn GridSearchCV pipeline. But it did not work when I included the n_jobs = -1 parameter.

def baseline_model():
    model = Sequential()
    model.add(Dense(128, input_shape = (X.shape[1],), activation = 'relu'))
    model.add(Dense(128, activation = 'relu'))
    model.add(Dense(128, activation = 'relu'))
    model.add(Dense(len(np.unique(y)), activation='softmax'))
    model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
    return model

model = KerasClassifier(build_fn = baseline_model)

# Define grid
random_state = 123
batch_size = [10, 120]
epochs = [10, 30]

param_grid = dict(batch_size = batch_size, epochs = epochs)

gridsearch = GridSearchCV(
    estimator = model,
    param_grid = param_grid,
    cv = 5,
    refit = True,
    n_jobs = -1
)

gridsearch.fit(X_train, y_train)

Error message:

BrokenProcessPool: A process in the executor was terminated abruptly while the future was running or pending.

But once I commented out the n_jobs = -1 parameter, it worked. Any ideas why?

desertnaut
  • 57,590
  • 26
  • 140
  • 166
griffinleow
  • 93
  • 12

0 Answers0