[英]ValueError: Unknown label type: continuous. When implementing regression
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.]我正在尝试使用神经网络预测出租车票价的价格,我设法针对一个优化器和给定数量的时期运行它,但是在实施 gridSearchCV() 以尝试不同的优化器和不同数量的时期时,它输出一个错误:[ValueError:未知标签类型:连续。]
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.
所有输入(19 个特征)都是数字、浮点数和整数。 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.但是您使用的包装器是用于分类的
KerasClassifier
。 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.改用
KerasRegressor
作为包装器,它应该可以正常工作。
model = KerasRegressor(build_fn=create_model,
epochs=50,
verbose=0)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.