2016-12-06 12 views
0

Titanic Problem on Kaggleを解決しようとしていますが、特定のテストデータの出力を得る方法がわかりません。TensorFlow - 予測できない

私は正常make_prediction(x, test_x)

x = tf.placeholder('float', [None, ip_features]) 
... 
def make_prediction(x, test_data): 
    with tf.Session() as sess : 
    sess.run(tf.global_variables_initializer()) 
    prediction = sess.run(y, feed_dict={x: test_data}) 
    return prediction 


私は戻って予測が含まれているnp.arrayを取得するには、この場合test_datanp.arrayを渡す方法を確認していない方法をネットワークを訓練し、呼び出す0/1

Link to Full Code

答えて

1

私はあなたのtrain_neural_networkmake_predictionは1つの関数として機能します。 tf.nn.softmaxをモデル関数に適用すると、値の範囲は0〜1(確率として解釈される)になり、tf.argmaxは高い確率で列番号を抽出します。この場合のyplaceholderはワンホットエンコードする必要があることに注意してください。 (ここでYをワンホット・エンコーディングでない場合は、pred_y=tf.round(tf.nn.softmax(model))は0にsoftmaxの出力を変換するでしょうか1)

def train_neural_network_and_make_prediction(train_X, test_X): 

    model = neural_network_model(x) 
    cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(model, y)) 
    optimizer = tf.train.AdamOptimizer().minimize(cost) 
    pred_y=tf.argmax(tf.nn.softmax(model),1) 

    ephocs = 10 

    with tf.Session() as sess : 
     tf.initialize_all_variables().run() 
     for epoch in range(ephocs): 
      epoch_cost = 0 

      i = 0 
      while i< len(titanic_train) : 
       start = i 
       end = i+batch_size 
       batch_x = np.array(train_x[start:end]) 
       batch_y = np.array(train_y[start:end]) 

       _, c = sess.run([optimizer, cost], feed_dict={x: batch_x, y: batch_y}) 
       epoch_cost += c 
       i+=batch_size 
      print("Epoch",epoch+1,"completed with a cost of", epoch_cost) 
     # make predictions on test data 
     predictions = pred_y.eval(feed_dict={x : test_X}) 
    return predictions 
+0

はあまり 'pred_y = tf.round(tf.nn.softmax(モデルありがとう)) 'は私が探していたものです:) –

関連する問題