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

Tensorflow 如何提高LSTM、GRU递归神经网络的分类精度,tensorflow,deep-learning,lstm,recurrent-neural-network,gated-recurrent-unit,Tensorflow,Deep Learning,Lstm,Recurrent Neural Network,Gated Recurrent Unit,Tensorflow中的二进制分类问题: 我已经阅读了在线教程,并尝试将其应用于使用门控循环单元(GRU)的实时问题。我已经尽了我所知的一切可能来改进分类 1) 已开始添加堆叠的RNN(GRU)层 2) 增加每个RNN层的隐藏单位 3) 增加了隐藏层的“sigmoid”和“RelU”激活功能 4) 规范化输入数据 5) 更改了超参数 请找到指向数据集的链接: 如果您可以浏览数据集,它有“正常”和“非正常”标签。我已将“正常”编码为“10”,将“异常”编码为“01”。我还将数据集更改为以下形状的

Tensorflow中的二进制分类问题:

我已经阅读了在线教程,并尝试将其应用于使用门控循环单元(GRU)的实时问题。我已经尽了我所知的一切可能来改进分类

1) 已开始添加堆叠的RNN(GRU)层 2) 增加每个RNN层的隐藏单位 3) 增加了隐藏层的“sigmoid”和“RelU”激活功能 4) 规范化输入数据 5) 更改了超参数

请找到指向数据集的链接:

如果您可以浏览数据集,它有“正常”和“非正常”标签。我已将“正常”编码为“10”,将“异常”编码为“01”。我还将数据集更改为以下形状的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}))    

听起来你走对了方向。我会尝试将你的训练数据可视化,以确保它如你所期望的那样减少

你有没有理由认为你应该获得更高的准确度?这可能是你能用这么多数据做的最好的了。提高模型性能的最佳方法之一是获取更多数据;有可能获得更多的数据吗


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

非常感谢fbt先生,你说得对,我使用的数据集的准确性是有效的。在训练我的第一个模型(案例1)时,我先走了一步,对样本进行了洗牌。当我使用原始数据集(原始大小的非缓冲数据集)时,模型表现得更好,有效精度更高(案例2)。我确保在这两种情况下,我不仅仅考虑“准确度”来衡量我的模型的性能。如果你在寻找其他指标,F1、召回率和准确度是准确度之外的好指标;卡帕是另一个强大的。这是我的新帐户。当我试图对你的答案进行投票时,它显示了这样一条信息:“投票记录在案,但不会公开显示,因为我的声誉不高”,这是合法的。我想你可以点击复选标记,将答案标记为“已接受,无信誉”。