我正在尝试将神经网络用于 python 中的回归问题,但神经网络的输出是一条水平直线,为零。我有一个输入,显然是一个输出。这是我的代码:
def baseline_model():
# create model
model = Sequential()
model.add(Dense(1, input_dim=1, kernel_initializer='normal', activation='relu'))
model.add(Dense(4, kernel_initializer='normal', activation='relu'))
model.add(Dense(1, kernel_initializer='normal'))
# Compile model
model.compile(loss='mean_squared_error',metrics=['mse'], optimizer='adam')
model.summary()
return model
# evaluate model
estimator = KerasRegressor(build_fn=baseline_model, epochs=50, batch_size=64,validation_split = 0.2, verbose=1)
kfold = KFold(n_splits=10)
results = cross_val_score(estimator, X_train, y_train, cv=kfold)
我也尝试过不同的权重初始化器(Xavier 和 He),但没有成功!非常感谢你的帮助
哈士奇WWW
Helenr
相关分类