【问题标题】:How can I improve the classification accuracy of LSTM,GRU recurrent neural networks如何提高 LSTM、GRU 递归神经网络的分类精度
【发布时间】:2017-12-14 11:13:31
【问题描述】:

Tensorflow 中的二元分类问题:

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

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

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

如果您可以浏览数据集,则它具有“正常”和“非正常”标签。我将“正常”编码为“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}))    

【问题讨论】:

    标签: tensorflow deep-learning lstm recurrent-neural-network gated-recurrent-unit


    【解决方案1】:

    听起来您走在正确的轨道上。我会尝试可视化您的训练数据,以确保它按照您的预期减少。

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

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

    【讨论】:

    • 非常感谢 Mr.fbt,你说得对,我使用的数据集的准确性是有效的。在训练我的第一个模型(案例 1)时,我领先一步,对样本进行了洗牌。当我使用原始数据集(具有原始大小的未打乱数据集)时,该模型以较高的有效精度表现得更好(案例 2)。我确保在这两种情况下衡量我的模型的性能时,我不仅考虑“单独的准确性”。
    • 如果你在寻找其他指标,除了准确率之外,F1、召回率和精度都是不错的; Kappa 是另一个强大的人。
    • 这是我的新帐户。当我尝试为您的答案投票时,它显示消息“投票已记录但未公开显示,因为我的声誉较低”
    • 这是合法的。我认为您可以单击复选标记将答案标记为已接受而没有声誉。
    猜你喜欢
    • 1970-01-01
    • 2021-04-25
    • 2015-12-15
    • 2016-11-22
    • 1970-01-01
    • 2023-01-28
    • 1970-01-01
    • 2023-03-29
    • 1970-01-01
    相关资源
    最近更新 更多