有谁知道我如何提高 RNN 的准确性

时间:2021-03-13 14:21:06

标签: python keras

我正在使用 NSL-KDD 数据集并使用 KDDTrain+ 和 KDDTest+ 进行训练和测试,所有数据都已使用 min-man 归一化和一种热编码等进行处理和归一化。我得到的最佳准确率为 80%并且处于二元分类中,但我似乎无法得到比这更好的东西,有人可以帮我吗?下面是RNN的代码

batch_size = 64
epochs = 50
layer_size = 64
drop_out = 0.8

if True: 
    model = Sequential()
    model.add(LSTM(layer_size,input_shape =(1, 121)))
    model.add(Dropout(drop_out))
    model.add(Dense(1))
    model.add(Activation('sigmoid'))
    model.compile(loss='binary_crossentropy', optimizer='adam' , metrics=['accuracy'])

    model.summary()

    history = model.fit(x_train_binary, y_train2, batch_size=batch_size, epochs=epochs,  validation_data=(x_test_binary, y_test2))

    # get predictions on the test set
    y_pred = model.predict_classes(x_test_binary)
    
    # reshape the predictions
    y_pred = y_pred.reshape(y_pred.shape[0])

    # get performance scores
    print("Accuracy",accuracy_score(y_test2,y_pred))
    print("precision_score",precision_score(y_test2,y_pred ))
    print("recall",recall_score(y_test2,y_pred ))

0 个答案:

没有答案