【发布时间】:2018-12-29 15:16:06
【问题描述】:
我正在尝试构建一个神经网络来预测 63 个输入中的 3 个输出值。我有一个包含两个形状为 [8100, 63] 和 [8100, 3] 的 numpy 数组的数据集,但是当我尝试将它们提供给 Keras 时,模型不会收敛,并且均方误差在 10^11 的区域内.
我用来计算数据的函数没有任何非线性属性,所以我首先认为一两层就足够了。三层的 MSE 仍然在 10^10 的范围内,我不确定我做错了什么。
回归应该返回三个可以大于 1 的绝对值 - 这就是我没有使用 softmax 层的原因。
如果有任何意见或帮助,我将不胜感激!
import numpy as np
from keras.models import *
from keras.layers import Dense
from keras import optimizers
from keras.utils import plot_model
np.random.seed(7)
#Define Input
tf_features_64 = np.load("IN.npy")
tf_labels_64 = np.load("OUT.npy")
tf_features_32 = tf_features_64.astype(np.float32)
tf_labels_32 = tf_labels_64.astype(np.float32)
X = tf_features_32
Y = tf_labels_32
#create Layers
visible = Input(shape=(63,))
x = Dense(100, activation='relu')(visible)
x = Dense(100, activation='relu')(x)
x = Dense(100, activation='relu')(x)
x = Dense(70, activation='relu')(x)
x = Dense(30, activation='relu')(x)
output = Dense(3)(x)
Optimizer = optimizers.adam(lr=0.001)
model = Model(inputs=visible, outputs = output)
model.compile(optimizer=Optimizer,
loss='categorical_crossentropy',
metrics=['mse']
)
model.fit(X, Y, epochs=400, batch_size=300, shuffle=True)
print(model.summary)
【问题讨论】:
-
你能分享你的数据集吗?
标签: python machine-learning keras regression