gpt4 book ai didi

python - 基本的神经网络预测?

转载 作者:行者123 更新时间:2023-11-30 09:34:33 24 4
gpt4 key购买 nike

我正在研究这个非常基本的神经网络 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))

最佳答案

我不知道这是否准确地回答了你的问题,但我只是在玩玩与你的代码并决定尝试一些东西。您的 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]

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

关于python - 基本的神经网络预测?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46535855/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com