I am trying to predict the price of taxi fares using a neural network, I managed to run it for one optimizer and for a given number of epochs, but when implementing gridSearchCV() to try out different optimizers and different amounts of epochs it outputs an error: [ValueError: Unknown label type: continuous.]
def create_model(activation = 'relu', optimizer='adam'):
model = keras.models.Sequential([
keras.layers.Dense(128, activation=activation),
keras.layers.Dense(64, activation=activation),
keras.layers.Dense(32, activation='sigmoid'),
keras.layers.Dense(1)
])
model.compile(optimizer=optimizer, loss='mean_squared_error') #, metrics=['neg_mean_squared_error'])
return model
model = KerasClassifier(build_fn=create_model,
epochs=50,
verbose=0)
# activations = ['tanh', 'relu', 'sigmoid']
optimizer = ['SGD', 'RMSprop', 'Adadelta', 'Adam', 'Adamax', 'Nadam']
epochs = [50, 100, 150, 200, 250, 300]
# batches = [32, 64, 128, 0]
param_grid = dict(optimizer = optimizer, # activation=activations,
epochs=epochs # batch_size=batches
)
grid = GridSearchCV(
estimator=model,
param_grid=param_grid,
n_jobs=-1,
cv=3,
scoring='neg_mean_squared_error',
verbose=2
)
grid_result = grid.fit(train_in, train_out)
The last part line of the code, fitting the model is outputing such error. All the inputs (19 features) are numerical, floats and integers. The output is a float value.
You mention wanting to implement a regression task. But the wrapper you are using is the KerasClassifier
for classification. This is not meant for regression with continuous target. Hence the error message for classifiers
ValueError: Unknown label type: continuous
Use the KerasRegressor
instead as a wrapper, and it should work fine.
model = KerasRegressor(build_fn=create_model,
epochs=50,
verbose=0)