2017-12-09 3 views
2
import tensorflow as tf 
import os 
import sklearn.preprocessing 
import pandas as pd 
import numpy as np 

print(os.getcwd()) 
os.chdir("C:/Users/jbnu/Documents/양지성/Scholar/정규학기/3-2/데이터마이닝실습/프로젝트/현행/bank-additional/bank-additional") 

로 자리 텐서 '자리 표시 자'에 대한 값을 공급해야한다 가져 오기 및 관리 데이터 세트당신은 DTYPE 플로트 (Tensorflow)

bank = pd.read_csv("bank4.csv", index_col=False) 

tf.reset_default_graph() 
keep_prob = tf.placeholder(tf.float32) 
learning_rate = 0.003 

x_data = bank.ix[:,0:9]; print(x_data) 
y_data = bank.ix[:, [-1]]; print(y_data) 
x_data = sklearn.preprocessing.scale(x_data).astype(np.float32); print(x_data) 
y_data = y_data.astype(np.float32) 

.

X = tf.placeholder(tf.float32, [None, 9]); print(X) 
Y = tf.placeholder(tf.float32, [None, 1]) 

# Layer 1 
W1 = tf.get_variable("weight1", shape=[9,15], dtype = tf.float32, 
        initializer=tf.contrib.layers.xavier_initializer()) 
b1 = tf.get_variable("bias1", shape=[15], dtype = tf.float32, 
        initializer=tf.contrib.layers.xavier_initializer()) 
layer1 = tf.nn.relu(tf.matmul(X, W1) + b1) 
layer1 = tf.nn.dropout(layer1, keep_prob=keep_prob) 

# Layer 2 
W2 = tf.get_variable("weight2", shape=[15,15], dtype = tf.float32, 
        initializer=tf.contrib.layers.xavier_initializer()) 
b2 = tf.get_variable("bias2", shape=[15], dtype = tf.float32, 
        initializer=tf.contrib.layers.xavier_initializer()) 
layer2 = tf.nn.relu(tf.matmul(layer1, W2) + b2) 
layer2 = tf.nn.dropout(layer2, keep_prob=keep_prob) 

# Layer 3 
W3 = tf.get_variable("weight3", shape=[15,15], dtype = tf.float32, 
        initializer=tf.contrib.layers.xavier_initializer()) 
b3 = tf.get_variable("bias3", shape=[15], dtype = tf.float32, 
        initializer=tf.contrib.layers.xavier_initializer()) 
layer3 = tf.nn.relu(tf.matmul(layer2, W3) + b3) 
layer3 = tf.nn.dropout(layer3, keep_prob=keep_prob) 

# Output Layer 
W4 = tf.get_variable("weight4", shape=[15,1], dtype = tf.float32, 
        initializer=tf.contrib.layers.xavier_initializer()) 
b4 = tf.get_variable("bias4", shape=[1], dtype = tf.float32, 
        initializer=tf.contrib.layers.xavier_initializer()) 
hypothesis = tf.sigmoid(tf.matmul(layer3, W4) + b4) 
hypothesis = tf.nn.dropout(hypothesis, keep_prob=keep_prob) 

비용 함수 및 최적화를 정의.

# Launch graph 
with tf.Session() as sess: 
    sess.run(tf.global_variables_initializer()) 

    for step in range(10001): 
     sess.run(train, feed_dict={X: x_data, Y: y_data}) 
     if step % 1000 == 0: 
      print("step: ", step, sess.run(cost, feed_dict={X: x_data, Y: y_data}), sep="\n") 

    # Accuracy report 
    h, c, a = sess.run([hypothesis, predicted, accuracy], 
         feed_dict={X: x_data, Y: y_data}) 
    print("\nHypothesis: ", h, "\nCorrect: ", c, "\nAccuracy: ", a) 

cost = -tf.reduce_mean(Y * tf.log(hypothesis) + (1 - Y) * tf.log(1 - hypothesis)) 

train = tf.train.AdamOptimizer(learning_rate=learning_rate).minimize(cost) 

predicted = tf.cast(hypothesis > 0.5, dtype=tf.float32) 
accuracy = tf.reduce_mean(tf.cast(tf.equal(predicted, Y), dtype=tf.float32)) 

교육과 정확성을 테스트 내 NN가 작동하지 않는 이유를 모르겠어요.

나는 계속해서 "자리 표시 자 텐서 'Placeholder'에 dtype float 값을 입력해야합니다. 모든 값은 float32입니다.

또한 드롭 아웃 속도에 feed_dict 오류가 발생합니다. 코드를 실행하고 잘못된 점을 알려주십시오. 그것은 드롭 아웃 keep_prob 자리에 대해 불평

답변

0

:

keep_prob = tf.placeholder(tf.float32) 

당신은 X와 함께 feed_dict에 제공하고 Y 또는 당신이 모든 시간을 통과하지 않으려면, 그것을 tf.placeholder_with_default을해야 하나.