我正在尝试使用GridSearch查找最佳参数,如下所示:
def MultiPerceptron(optimizer = 'adam', loss = 'binary_cross_entropy', kernel_initializer = 'random_uniform', activation = 'relu', units = 16):
model = Sequential()
model.add(InputLayer(30))
model.add(Dense(units = units, activation = activation, kernel_initializer = kernel_initializer))
model.add(Dense(units = units, activation = activation, kernel_initializer = kernel_initializer))
model.add(Dense(units = 1, activation = 'sigmoid'))
model.compile(optimizer = optimizer, loss = loss, metrics =['binary_accuracy'])
return model
classifier = KerasClassifier(build_fn = MultiPerceptron, validation_split = 0.1, validation_batch_size = 50)
param = {'batch_size': [10, 30],
'epochs': [50, 100],
'optimizer': ['adam', 'sgd'],
'loss': ['binary_crossentropy', 'hinge'],
'kernel_initializer': ['random_uniform', 'normal'],
'activation': ['relu', 'tanh'],
'units': [16, 8]}
search = GridSearchCV(estimator = classifier, param_grid = param, scoring = 'accuracy', cv = 5)
search = search.fit(x,y)
我得到以下错误:
ValueError: Invalid parameter activation for estimator KerasClassifier.
This issue can likely be resolved by setting this parameter in the KerasClassifier constructor:
`KerasClassifier(activation=relu)`
Check the list of available parameters with `estimator.get_params().keys()`
3条答案
按热度按时间q7solyqu1#
我认为他们改变了一些东西,因为我只能通过将
activation=relu
参数传递给KerasClassifier
来使它工作。此处不需要其他参数。
bq9c1y662#
我也遇到了同样的问题。下面的代码在使用keras时运行得很好。
但在切换到Scikeras后,我总是得到一个ValueError:
我在KerasClassifiet中添加了lambda_parameter=0.01来解决这个问题
ilmyapht3#
在KerasClassifier构造函数中使用激活和层
然后
它的工作!最后得到了下面的输出: