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

前端 未结 16 1277
一生所求
一生所求 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:09

    Just in case some is looking for the same in MULTI-CLASS Example

    def perf_measure(y_actual, y_pred):
        class_id = set(y_actual).union(set(y_pred))
        TP = []
        FP = []
        TN = []
        FN = []
    
        for index ,_id in enumerate(class_id):
            TP.append(0)
            FP.append(0)
            TN.append(0)
            FN.append(0)
            for i in range(len(y_pred)):
                if y_actual[i] == y_pred[i] == _id:
                    TP[index] += 1
                if y_pred[i] == _id and y_actual[i] != y_pred[i]:
                    FP[index] += 1
                if y_actual[i] == y_pred[i] != _id:
                    TN[index] += 1
                if y_pred[i] != _id and y_actual[i] != y_pred[i]:
                    FN[index] += 1
    
    
        return class_id,TP, FP, TN, FN
    

提交回复
热议问题