我正在使用 LSTM 进行时间序列预测,我的数据高度倾斜,具有类权重197.16865807 : 0.50127117
Label 0 : 25359和_Label 1 : 9974641
我的模型如下所示
n_input = 100
n_features = 36
class_weights = class_weight.compute_class_weight('balanced',
np.unique(y_target),
y_target)
model = tf.keras.Sequential([
tf.keras.layers.LSTM(64, activation='tanh', input_shape=(n_input, n_features),return_sequences = True),
tf.keras.layers.LSTM(64, activation='tanh',return_sequences = True),
tf.keras.layers.LSTM(64, activation='tanh',return_sequences = True),
tf.keras.layers.LSTM(64, activation='tanh',return_sequences = True),
tf.keras.layers.Dense(128, activation='relu'),
tf.keras.layers.Dense(1,activation='sigmoid')])
model.compile(optimizer='adam', loss= 'binary_crossentropy' ,metrics=METRICS)
model.fit_generator(train_generator, epochs= 1,steps_per_epoch=len(train_generator),class_weight=class_weight)
我尝试了以下方法来处理我不变的准确性和损失值。
- 我试图调整班级权重,但似乎不起作用,我的预测都是
1 - 我尝试使用
RandomSamplerfromimblearn对我的数据进行欠采样,但准确率停留在 50% - 我试图将损失函数更改为
weighted_cross_entropy_with_logits,但我没有找到任何示例显示如何在Sequential上面的模型中使用它
我觉得我的模型不能预测结果,因为当我输入平衡数据集时,准确度大约是50%,当我输入不平衡数据集时,准确度是99%。
谁能帮我这个?我想知道这是我的模型的问题,还是我的数据集不平衡的问题
谢谢!