我的张量流代码不能很好地进行银行分析

时间:2017-11-14 07:18:25

标签: tensorflow

我正在研究张量流,我写了一些代码,但效果不好。

数据是从uci:http://archive.ics.uci.edu/ml/datasets/Bank+Marketing

下载的

我想找到订阅定期存款的客户,但匹配的结果是0。

我使用3层神经网络和sigmod进行输出。

我的代码是这样的,请帮助我。

hidden_layer1 = 200
hidden_layer2 = 200


x = tf.placeholder(tf.float32,[None,16])
y = tf.placeholder(tf.float32,[None,1])

Weights_L1 = tf.Variable(tf.random_normal([16,hidden_layer1]))
biases_L1 = tf.Variable(tf.random_normal([1,hidden_layer1]))

Wx_plus_b_L1 = tf.matmul(x,Weights_L1) + biases_L1
L1=tf.nn.relu(Wx_plus_b_L1)



Weights_L2 = tf.Variable( tf.random_normal([hidden_layer1,1]))
biases_L2 = tf.Variable( tf.random_normal([1,1]))

Wx_plus_b_L2 = tf.matmul(L1,Weights_L2) + biases_L2


pred = tf.nn.sigmoid(Wx_plus_b_L2)



loss = tf.reduce_mean(tf.square(y-pred))


learning_rate=0.05
train_step = tf.train.GradientDescentOptimizer(learning_rate).minimize(loss)

pred_correct = tf.equal(y,pred)
accuracy = tf.reduce_mean(tf.cast(pred_correct,tf.float32))

batch_num = 0
with tf.Session() as ss:
    ss.run(tf.global_variables_initializer())

    for step in range(500):

        ss.run(train_step,feed_dict={x:bank_train_x,y:bank_train_y})
        if step%100==0:
            batch_num = batch_num +1

            acc1 = ss.run(accuracy,feed_dict={x:bank_train_x,y:bank_train_y})
            print("train acc"+ str(step) + ", " + str(acc1) +" ,  batch_num:" + str(batch_num))
            #print(ss.run(learning_rate,feed_dict={global_:step}))
    p = ss.run(pred,feed_dict={x:bank_train_x,y:bank_train_y})
    acc2 = ss.run(accuracy,feed_dict={x:bank_test_x,y:bank_test_y})
    print("test acc" + str(acc2))

def calc(pred,y):
    l = y.shape[0]
    a = 0
    b=0
    c=0
    d=0
    for i in range(l):
        if (p[i] >0.5 and y[i] == 0):
            a = a +1
        elif (p[i] >0.5 and y[i] == 1):
            b = b+1
        elif (p[i] <0.5 and y[i] == 0):
            c = c+1
        elif (p[i] <0.5 and y[i] == 1):
            d = d +1 
    print(a,b,c,d)

calc(p,bank_train_y)
#the result is 169 0 34959 4629 

0 个答案:

没有答案