2017-12-25 16 views
1

나는 Tensorflow를 처음 사용하여 코드를 가지고있는 첫 번째 신경망 분류기를 실행했습니다. https://www.tensorflow.org/get_started/estimator. 성공적으로 작동했지만 정밀도 만 보여주었습니다. 어떻게 혼용 행렬을 출력 할 수 있습니까? 2 개의 레이블 만 있습니다. 1 및 0입니다.TensorFlow Estimator 혼란 행렬

이것은 코드의 마지막 부분입니다. 그것은 링크와 동일합니다.

# 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

새 샘플, 클래스 예측과 같은 결과가 나옵니다 : [array ([b'0 '], dtype = object), array ([b'0 '], dtype = object), 배열 ([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)