Scikit-learn: How to obtain True Positive, True Negative, False Positive and False Negative

前端 未结 16 1284
一生所求
一生所求 2020-12-02 04:25

My problem:

I have a dataset which is a large JSON file. I read it and store it in the trainList variable.

Next, I pre-process

16条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-02 05:16

    The one liner to get true postives etc. out of the confusion matrix is to ravel it:

    from sklearn.metrics import confusion_matrix
    
    y_true = [1, 1, 0, 0]
    y_pred = [1, 0, 1, 0]   
    
    tn, fp, fn, tp = confusion_matrix(y_true, y_pred).ravel()
    print(tn, fp, fn, tp)  # 1 1 1 1
    

提交回复
热议问题