gpt4 book ai didi

python - Keras 性能不佳(损失函数和优化函数?)

转载 作者:太空宇宙 更新时间:2023-11-04 02:44:19 25 4
gpt4 key购买 nike

在过去的 2 周里,我一直在与我的 NN 作斗争。目的是根据几个

  • 数值变量(纬度和经度)
  • 分类变量(数字编码)(一天中的小时、星期几等)

这是最简单的版本

X_train = trainData.as_matrix(columns=["fareDistance","hour","day","pickup_longitude","pickup_latitude","dropoff_longitude","dropoff_latitude"])    
Y_train = np.array(trainData["trip_duration"])
model = Sequential()
model.add(Dense(32, input_dim=7, activation='linear'))
model.add(Dense(12, activation='linear'))
model.add(Dense(1, activation='linear'))
model.compile(loss='mean_absolute_percentage_error', optimizer='adagrad', metrics=['accuracy'])
model.summary()
model.fit(X_train, Y_train, epochs=10, validation_split=0.2)

我还尝试合并两种不同的模型,一方面针对数值变量,另一方面针对分类变量,但这并没有改变任何事情。根据损失和优化函数的组合,损失和准确度保持完全相同(acc.0.0016)或者我什至没有非空acc。

我的一个 friend 在纯 TensorFlow 中复制了神经网络并得到了同样的结果

Train on 233383 samples, validate on 58346 samples 
Epoch 1/20 233383/233383 [==============================] - 15s - loss: 45.9550 - acc: 0.0016 - val_loss: 46.2514 - val_acc: 0.0014
Epoch 2/20 233383/233383 [==============================] - 15s - loss: 45.8675 - acc: 0.0014 - val_loss: 46.2675 - val_acc: 0.0015
Epoch 3/20 233383/233383 [==============================] - 15s - loss: 45.8465 - acc: 0.0015 - val_loss: 46.2131 - val_acc: 0.0013
Epoch 4/20 233383/233383 [==============================] - 15s - loss: 45.8283 - acc: 0.0014 - val_loss: 46.2478 - val_acc: 0.0016
Epoch 5/20 233383/233383 [==============================] - 15s - loss: 45.8214 - acc: 0.0015 - val_loss: 46.2043 - val_acc: 0.0013
Epoch 6/20 233383/233383 [==============================] - 14s - loss: 45.8122 - acc: 0.0014 - val_loss: 46.2526 - val_acc: 0.0014
Epoch 7/20 233383/233383 [==============================] - 12s - loss: 45.7990 - acc: 0.0015 - val_loss: 46.1821 - val_acc: 0.0014
Epoch 8/20 233383/233383 [==============================] - 12s - loss: 45.7964 - acc: 0.0016 - val_loss: 46.1761 - val_acc: 0.0013
Epoch 9/20 233383/233383 [==============================] - 11s - loss: 45.7898 - acc: 0.0015 - val_loss: 46.1804 - val_acc: 0.0016

我是否遗漏了一些东西——比如一些大的、明显的东西——这可以解释为什么任何改变激活、损失或优化函数的尝试最终都会做同样的事情?

提前致谢D.

最佳答案

试试这个:

X_train = trainData.as_matrix(columns=["fareDistance","hour","day","pickup_longitude","pickup_latitude","dropoff_longitude","dropoff_latitude"])    
Y_train = np.array(trainData["trip_duration"])
model = Sequential()
model.add(Dense(32, input_dim=7, activation='elu'))
model.add(Dense(12, activation='elu'))
model.add(Dense(1, kernel_initializer='normal'))
model.compile(loss='mean_absolute_percentage_error', optimizer='rmsprop')
model.summary()
model.fit(X_train, Y_train, epochs=10, validation_split=0.2)

您也可以试试 adam 优化器。

model.compile(loss='mean_absolute_percentage_error', optimizer='adam')

更新:

  • 如果上面的代码对您没有帮助,则意味着您的输入数据未规范化或非常脏

关于python - Keras 性能不佳(损失函数和优化函数?),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45586978/

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