我创建了LSTM RNN,以便根据gps坐标预测某人是否在驾驶。 这是数据示例(注意:x,y,z是从lat,lon转换而成的3d坐标):
x y z trip_id,mode_cat,weekday,period_of_day
datetime id
2011-08-27 06:13:01 20 0.650429 0.043524 0.758319 1 1 1 0
2011-08-27 06:13:02 20 0.650418 0.043487 0.758330 1 1 1 0
2011-08-27 06:13:03 20 0.650421 0.043490 0.758328 1 1 1 0
2011-08-27 06:13:04 20 0.650427 0.043506 0.758322 1 1 1 0
2011-08-27 06:13:05 20 0.650438 0.043516 0.758312 1 1 1 0
当我训练我的网络时,我的training_loss和validation_loss都降低了,但是在第一个时期精度达到1.0。我确保我的培训和测试数据不相同。 这是我如何分割训练和测试数据的方法:
t_num_test = df["trip_id"].iloc[-1]*4//5
train_test_df = df.loc[df["trip_id"]<=t_num_test].copy(deep=True)
test_test_df = df.loc[df["trip_id"]>t_num_test].copy(deep=True)
features_train = train_test_df[["x","y","z","datetime","id","trip_id","mode_cat","weekday","period_of_day"]]
features_train.set_index(["datetime","id"],inplace=True)
dataset_train_x = features_train[["x","y","z","trip_id","weekday","period_of_day"]].values
dataset_train_y = features_train[["mode_cat"]].values
features_test = test_test_df[["x","y","z","datetime","id","trip_id","mode_cat","weekday","period_of_day"]]
features_test.set_index(["datetime","id"],inplace=True)
dataset_test_x = features_test[["x","y","z","trip_id","weekday","period_of_day"]].values
dataset_test_y = features_test[["mode_cat"]].values
这是我建立网络的方式:
single_step_model = tf.keras.models.Sequential()
single_step_model.add(tf.keras.layers.LSTM(1,
input_shape=x_train_single.shape[-2:]))
single_step_model.add(tf.keras.layers.Dropout(0.2))
single_step_model.add(tf.keras.layers.Dense(1, activation='sigmoid'))
single_step_model.compile(optimizer=tf.keras.optimizers.Adam(learning_rate=0.0001), loss='binary_crossentropy',
metrics=['accuracy'])
.
.
.
single_step_history = single_step_model.fit(train_data_single, epochs=epochs,
steps_per_epoch=evaluation_interval,
validation_data=test_data_single,
validation_steps=60)
And here is the graph displaying training_loss, validation_loss and accuracy
什么可能导致此结果? 如果有问题,我将使用大约500,000个数据点和大约8000个唯一的trip_id。
请告知
答案 0 :(得分:1)
希望这会有所帮助!
我能想到的几个案例
您的数据集有偏差。是否可以使大多数输入数据倾斜?检查其中的mode_cat值的百分比。 (全部都是1,或者大多数都是1?)
您的X值可能具有作为函数的特征/列y是x值的函数(例如y_val = m * x_col2 + x_col3吗?)
学习准确性非常好,但是请尝试使用f1 score / confusion_matrix之类的东西。
链接: