카테고리 없음
F1 Score 설명 및 코드
벤치마킹
2019. 5. 24. 22:09
NLP 를 하다보면 한번씩 성능에 관한 평가를 하게 된다.
F1 Score 라고 나는 hashTag 성능 측정에 해당 모델을 적용해 보았다..
그 결과는 처참했지만
즉 True 라고 예측 것 중에 실제로 True 인것과 ==> Precision
True 중에서 True 가 맞는 놈의 균형 ==> Recall
P = TP + FN
N = FP + TN
F1 score = 2 * (Precision * Recall) / (Precision + Recall)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | def hash_evaluation(TagName, predicts, answers): _f1 = 0 #print("answers len: ", len(answers)) for i, (predict, answer) in enumerate(zip(predicts, answers)): # tp = 0 fn = 0 for tag in answer: if(tag in predict): tp += 1 else: fn += 1 fp = len(predict) - tp if((tp+fp) == 0): precision = 0 recall = 0 else: precision = tp / (tp + fp) recall = tp / (tp + fn) if((precision + recall) == 0): _f1 += 0 else: _f1 += 2 * precision * recall / (precision + recall) f1_score['f1'] = _f1/len(answers) global AllCnt AllCnt = AllCnt + 1 global AllScore AllScore = AllScore + _f1/len(answers) return f1_score | cs |