【发布时间】:2017-10-03 18:52:01
【问题描述】:
我正在查看来自https://machinelearningmastery.com/tutorial-first-neural-network-python-keras/ 的这个非常基本的神经网络。我用随机的数字数组和随机标签替换了使用的数据。
我假设由于输入是随机的,因此预测值应该在 0.50 左右,上下浮动一点。但是,当我这样做时,我得到了
[0.49525392, 0.49652839, 0.49729034, 0.49670222, 0.49342978, 0.49490061, 0.49570397, 0.4962129, 0.49774086, 0.49475089, 0.4958384, 0.49506786, 0.49696651, 0.49869373, 0.49537542, 0.49613148, 0.49636957, 0.49723724]
大约是 0.50,但永远不会超过。它适用于我使用的任何随机种子,所以这也不仅仅是巧合。对这种行为有什么解释吗?
# Create first network with Keras
from keras.models import Sequential
from keras.layers import Dense
import numpy as np
np.random.seed(90)
X_train = np.random.rand(18,61250)
X_test = np.random.rand(18,61250)
Y_train = np.array([0.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 0.0, 1.0,
0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0,])
Y_test = np.array([1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0,
1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0,])
_, input_size = X_train.shape
# create model
model = Sequential()
model.add(Dense(12, input_dim=input_size, init='uniform', activation='relu'))
model.add(Dense(8, init='uniform', activation='relu'))
model.add(Dense(1, init='uniform', activation='sigmoid'))
# Compile model
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
# calculate predictions
predictions = model.predict(X_test)
preds = [x[0] for x in predictions]
print(preds)
# Fit the model
model.fit(X_train, Y_train, epochs=100, batch_size=10, verbose=2, validation_data=(X_test,Y_test))
【问题讨论】:
标签: python machine-learning neural-network keras