2017-12-16 2 views
1

ねえ、私はテンソルフローがかなり新しいです。基本的に0/1に分類される分類モデルを構築しています。出力が1になる確率を予測する方法はありますか?ここでpredict_probaを使用できますか?それは広くtflearn.dnnで使用されていますが、私の場合はそれを行うための参照を見つけることができません。ここでクラスファイヤーテンソルの確率を予測する

def main(): 
    train_x,test_x,train_y,test_y = load_csv_data() 
    x_size = train_x.shape[1] 
    y_size = train_y.shape[1] 

    print(x_size) 
    print(y_size) 
    # variables 
    X = tf.placeholder("float", shape=[None, x_size]) 
    y = tf.placeholder("float", shape=[None, y_size]) 
    weights_1 = initialize_weights((x_size, h_size)) 
    weights_2 = initialize_weights((h_size, y_size)) 
    # Forward propagation 
    y_pred = forward_propagation(X, weights_1, weights_2) 
    predict = tf.argmax(y_pred, dimension=1) 
    # Backward propagation 
    cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(labels=y, logits=y_pred)) 
    updates_sgd = tf.train.GradientDescentOptimizer(sgd_step).minimize(cost) 
    # Start tensorflow session 

    with tf.Session() as sess: 

     init = tf.global_variables_initializer() 
     steps = 1 
     sess.run(init) 
     x = np.arange(steps) 
     test_acc = [] 
     train_acc = [] 
     print("Step, train accuracy, test accuracy") 
     for step in range(steps): 
      # Train with each example 
      batch_size = len(train_x) 
      avg_cost = 0 
      print(batch_size) 
      for i in range(len(train_x)): 
       _, c = sess.run([updates_sgd,cost], feed_dict={X: train_x[i: i + 1], y: train_y[i: i + 1]}) 
       print(c) 
       avg_cost += c/batch_size 

      train_accuracy = np.mean(np.argmax(train_y, axis=1) == 
            sess.run(predict, feed_dict={X: train_x, y: train_y})) 
      test_accuracy = np.mean(np.argmax(test_y, axis=1) == 
            sess.run(predict, feed_dict={X: test_x, y: test_y})) 

      print(avg_cost) 
      print("%d, %.2f%%, %.2f%%" 
        % (step + 1, 100. * train_accuracy, 100. * test_accuracy)) 

      test_acc.append(100. * test_accuracy) 
      train_acc.append(100. * train_accuracy) 

     predict = tf.argmax(y_pred,1) 
     test_data = load_test_data() 
     print(test_data) 
     pred = predict.eval(feed_dict={X:test_data}) 
     print(pred) 
     for x in range(0,100): 
      print(pred[x]) 
     print(np.unique(pred)) 
main() 

答えて

0

あなたは確率のARGMAXを取る:

predict = tf.argmax(y_pred, dimension=1) 

あなたは単にあなたが確率を取得する必要があります "y_pred" を返す場合。

+1

cool!ありがとう:) – sumit

関連する問題