我尝试使用Keras将a / b与mlp相匹配,这是我的代码:
x,y = [],[]
for i in range(100000):
k = []
for j in range(2):
k.append(random.random())
x.append(k)
y.append(k[0]/k[1])
x = np.array(x)
y = np.array(y)
trainx = x[:80000]
trainy = y[:80000]
valx = x[80000:]
valy = y[80000:]
model = Sequential()
model.add(Dense(512, activation='relu',input_shape=(len(trainx[0]),)))
model.add(Dropout(0.2))
model.add(Dense(512,activation='relu'))
model.add(Dropout(0.2))
model.add(Dense(1,activation='tanh'))
opt = optimizers.RMSprop()
model.compile(loss='mse', optimizer=opt, metrics=["mae"])
model.fit(trainx,trainy,batch_size=100,epochs=100,verbose=1,validation_data=(valx,valy))
,输出为:
80000/80000 [==============================] - 6s 78us/step - loss:25299.1590 - mean_absolute_error: 5.5678 - val_loss: 10557.5025 -val_mean_absolute_error: 4.5637
80000/80000 [==============================] - 4s 47us/step - loss: 25299.1220 - mean_absolute_error: 5.5502 - val_loss: 10557.5016 - val_mean_absolute_error: 4.5513
80000/80000 [==============================] - 4s 48us/step - loss: 25299.1225 - mean_absolute_error: 5.5475 - val_loss: 10557.5015 - val_mean_absolute_error: 4.5509
80000/80000 [==============================] - 4s 49us/step - loss: 25299.1219 - mean_absolute_error: 5.5462 - val_loss: 10557.5016 - val_mean_absolute_error: 4.5556
80000/80000 [==============================] - 4s 47us/step - loss: 25299.1223 - mean_absolute_error: 5.5456 - val_loss: 10557.5016 - val_mean_absolute_error: 4.5544
80000/80000 [==============================] - 4s 48us/step - loss: 25299.1221 - mean_absolute_error: 5.5451 - val_loss: 10557.5015 - val_mean_absolute_error: 4.5508
我不知道我的代码有什么问题。我还尝试sklearn.preprocessing.PolynomialFeatures
生成更多功能,但没有任何改变。