2017-12-25 5 views
1

私はTensorflowを初めて使用しています。私はちょうどhttps://www.tensorflow.org/get_started/estimatorのコードを取得した最初のニューラルネットワーク分類器を実行しました。 正常に動作しましたが、精度しか示されませんでした。 混乱行列を出力するにはどうしたらいいですか?私は2つのラベルしか持っていません。 1および0。TensorFlow Estimator Confusion Matrix

これはコードの最後の部分です。それはリンクと同じです。

# Train model. 
    classifier.train(input_fn=train_input_fn, steps=2000) 

    # Define the test inputs 
    test_input_fn = tf.estimator.inputs.numpy_input_fn(
     x={"x": np.array(test_set.data)}, 
     y=np.array(test_set.target), 
     num_epochs=1, 
     shuffle=True) 

    # Evaluate accuracy. 
    accuracy_score = classifier.evaluate(input_fn=test_input_fn)["accuracy"] 
+0

しかし、リンクのコードは '予測=リスト(classifier.predict(input_fn = predict_input_fn))を含む、いくつかのより多くの行を、'持っています。これらの行はあなたが望むものを与えませんか?テストデータに混乱行列を入れたいのであれば、これらの行で 'predict_input_fn'を' test_input_fn'に置き換えてください。 – Lior

+0

新しいサンプル、クラス予測のような結果が得られます:[ar​​ray([b'0 ']、dtype = object)、array ([b'0 ']、dtype = object)、array([b'0']。 –

+0

真陽性、偽陽性...結果はどのように生成できますか –

答えて

2

tf.confusion_matrixを使用して混同行列を生成することができます。具体的には、以下のようなものが動作するはずです:

labels = list(test_set.target) 
predictions = list(classifier.predict(input_fn=test_input_fn)) 
confusion_matrix = tf.confusion_matrix(labels, predictions)