小编Dan*_*el 的帖子

网格使用keras搜索隐藏层的数量

我正在尝试使用Keras和sklearn来优化我的NN的超参数.我正在使用KerasClassifier(这是一个分类问题).我正在尝试优化隐藏层的数量.我不知道如何用keras做到这一点(实际上我想知道如何设置函数create_model以最大化隐藏层的数量)有谁可以帮助我?

我的代码(只是重要部分):

## Import `Sequential` from `keras.models`
from keras.models import Sequential

# Import `Dense` from `keras.layers`
from keras.layers import Dense

def create_model(optimizer='adam', activation = 'sigmoid'):
  # Initialize the constructor
  model = Sequential()
  # Add an input layer
  model.add(Dense(5, activation=activation, input_shape=(5,)))
  # Add one hidden layer
  model.add(Dense(8, activation=activation))
  # Add an output layer 
  model.add(Dense(1, activation=activation))
  #compile model
  model.compile(loss='binary_crossentropy', optimizer=optimizer, metrics=
  ['accuracy'])
  return model
my_classifier = KerasClassifier(build_fn=create_model, verbose=0)# Create 
hyperparameter space
epochs = [5, 10]
batches = [5, 10, 100]
optimizers = …
Run Code Online (Sandbox Code Playgroud)

python neural-network hyperparameters keras

3
推荐指数
1
解决办法
3087
查看次数

标签 统计

hyperparameters ×1

keras ×1

neural-network ×1

python ×1