如何提高 LSTM、GRU 递归神经网络的分类精度

How can I improve the classification accuracy of LSTM,GRU recurrent neural networks

Tensorflow 中的二元分类问题:

我浏览了在线教程并尝试使用门控循环单元 (GRU) 将其应用于实时问题。我已经尝试了所有我知道的改进分类的可能性。

1) 开始添加堆叠 RNN(GRU) 层 2) 增加每个 RNN 层的隐藏单元 3) 为隐藏层添加了 "sigmoid" 和 "RelU" 激活函数 4)归一化输入数据 5) 改变了超参数

请找到 link 到数据集: https://github.com/madhurilalitha/Myfirstproject/blob/master/ApplicationLayerTrainingData1.txt

如果您可以浏览数据集,它有标签 "normal" 和 "other than normal"。我已将 "normal" 编码为“1 0”,将异常编码为“0 1”。我还将数据集更改为以下形状的 3D:

新火车形状 X (7995, 5, 40) 新列车Y的形状(7995、2) 新试X的形状(1994, 5, 40) 新测试 Y 的形状 (1994, 2)

我不太确定哪里缺少逻辑,有人可以帮我找出代码中的错误吗?

在测试数据上的分类准确率为52.3%。即使在训练数据上,它也能以相同的精度执行。请找到以下代码:

#Hyper Parameters for the model
learning_rate = 0.001   
n_classes = 2    
display_step = 100    
input_features = train_X.shape[1] #No of selected features(columns)    
training_cycles = 1000    
time_steps = 5 # No of time-steps to backpropogate    
hidden_units = 50 #No of GRU units in a GRU Hidden Layer   

#Input Placeholders
with tf.name_scope('input'):
    x = tf.placeholder(tf.float64,shape = [None,time_steps,input_features], name 
= "x-input")    
    y = tf.placeholder(tf.float64, shape = [None,n_classes],name = "y-input")
#Weights and Biases    
with tf.name_scope("weights"):
    W = tf.Variable(tf.random_normal([hidden_units,n_classes]),name = "layer-
weights")    

with tf.name_scope("biases"):
    b = tf.Variable(tf.random_normal([n_classes]),name = "unit-biases")     


# Unstack to get a list of 'time_steps' tensors of shape (batch_size, 
input_features)
x_ = tf.unstack(x,time_steps,axis =1)    

#Defining a single GRU cell
gru_cell = tf.contrib.rnn.GRUCell(hidden_units)    

#GRU Output
with tf.variable_scope('MyGRUCel36'):   
    gruoutputs,grustates = 
tf.contrib.rnn.static_rnn(gru_cell,x_,dtype=tf.float64)    

#Linear Activation , using gru inner loop last output
output = tf.add(tf.matmul(gruoutputs[-1],tf.cast(W,tf.float64)),tf.cast(b,tf.float64))

#Defining the loss function
cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(labels=y,logits = output))
optimizer = tf.train.AdamOptimizer(learning_rate=learning_rate).minimize(cost)

#Training the Model
sess = tf.InteractiveSession()    
sess.run(tf.global_variables_initializer())    
for i in range (training_cycles):   
    _,c = sess.run([optimizer,cost], feed_dict = {x:newtrain_X, y:newtrain_Y})

    if (i) % display_step == 0:
        print ("Cost for the training cycle : ",i," : is : ",sess.run(cost, feed_dict ={x :newtrain_X,y:newtrain_Y}))
correct = tf.equal(tf.argmax(output, 1), tf.argmax(y,1))    
accuracy = tf.reduce_mean(tf.cast(correct, 'float'))    
print('Accuracy on the overall test set is :',accuracy.eval({x:newtest_X, y:newtest_Y}))    

听起来你走对了路。我会尝试可视化您的训练数据,以确保它按照您的预期减少。

您是否认为应该获得更高的准确度?这可能是您可以使用这些数据量做的最好的事情。提高模型性能的最佳方法之一是获取更多数据;是否可以获得更多数据?

超参数优化是一个很好的方法;我会尝试使用不同的学习率、不同数量的隐藏层和不同大小的隐藏层。