【问题标题】:Basic Neural Net Predictions?基本的神经网络预测?
【发布时间】: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


    【解决方案1】:

    我不知道这是否准确地回答了你的问题,但我在玩 使用您的代码并决定尝试一下。您的 X 数据在 0 之间生成 和 1,所以我尝试在 0 到 10 之间生成它。这是 结果预测:

    [0.53419214, 0.55088341, 0.53190422, 0.52382213, 0.53469753, 0.53098464,
    0.51968938, 0.53249627, 0.52852863, 0.52497149, 0.52816379, 0.5457474,
    0.52565753, 0.5276686, 0.52042121, 0.52128422, 0.52535951, 0.52730507]
    

    如您所见,它现在产生的结果超过 0.5。因为你预测 在进行任何训练之前的输出,预测将完成 随机权重。会不会是网络还没适应 输入向量的分布?

    这些是训练后的预测:

    [0.43440229, 0.48104468, 0.49194154, 0.4766106, 0.50065982, 0.47388917,
    0.51052755, 0.50618082, 0.48478326, 0.4846094, 0.50018799, 0.4800632,
    0.4181695, 0.48307362, 0.5063237, 0.50420266, 0.47321039, 0.44235682]
    

    预测现在或多或少是平衡的。我得到这种 具有两种输入分布的输出。我认为这是一个问题 随机初始化的网络非常依赖于 你的输入数据。训练后它会正常化。

    【讨论】:

    • 谢谢!!我注意到网络有时会超过 50%,但我认为我正在做一些事情来使它有利于一方。训练后做预测更有意义。
    猜你喜欢
    • 1970-01-01
    • 2017-12-02
    • 2012-05-06
    • 2017-12-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-20
    相关资源
    最近更新 更多