2024년 8월 25일 일요일

데이터 분석 모델 성능 평가 지표

# F1의 공식

F1 = 2*(Precision*Recall) / (Precision+Recall)

# F1값 해석

F1값이 높으면 Precision과 Recall 모두 좋은 결과를 보인다는 것을 의미한다.
F1값이 낮으면 False Positive가 문제가 있는 것인지
False Negative가 문제가 있는 것인지 정확히 알 수가 없다.
따라서 이 경우에는 디버깅이 필요하다.

 

# TP, FP, FN, TN

- TP : 내가 1로 예측을 했는데 정답도 1인 경우, 즉 양성이라고 한 예측이 정답과 일치하는 경우에 TP입니다. 진짜 true로 양성 positive라고 한 경우인 것이죠
- FP는 내가 1로 예측을 했지만 정답은 0인 경우, 즉 양성이라고 한 예측이 정답과 불일치하는 경우가 FP입니다. 가짜 false로 양성 positive라고 한 경우인 것이죠
- FN은 내가 0으로 예측을 했지만 정답은 1인 경우, 즉 음성이라고 한 예측이 정답과 불일치하는 경우가 FN입니다. 가짜 false로 음성 negative라고 한 경우인 것이죠.
- TN는 내가 0으로 예측을 했는데 정답도 0인 경우, 즉 음성이라고 한 예측이 정답과 일치하는 경우에 TN입니다. 진짜 true로 음성 negative라고 한 경우인 것이죠

# Precision

precision=TP/(TP+FP)

 

# Recall

recall=TP/(TP+FN)

여기서 precision의 의미는 양성 positive라고 판단한 경우 중에 진짜 true 양성 positive인 확률입니다. 즉 정확도라고 보시면 됩니다.

recall은 실제로 양성 positive 케이스들에서 진짜 true 양성 positive로 예측에 성공한 확률입니다. 즉 내가 예측했어야하는 케이스들에서 놓치지 않고 예측해서 진짜를 잡아낸 경우라고 보시면 됩니다.


Accuracy

It’s the ratio of the correctly labeled subjects to the whole pool of subjects.
Accuracy is the most intuitive one.
Accuracy answers the following question: How many students did we correctly label out of all the students?
Accuracy = (TP+TN)/(TP+FP+FN+TN)
numerator: all correctly labeled subject (All trues)
denominator: all subjects

Precision

Precision is the ratio of the correctly +ve labeled by our program to all +ve labeled.
Precision answers the following: How many of those who we labeled as diabetic are actually diabetic?
Precision = TP/(TP+FP)
numerator: +ve labeled diabetic people.
denominator: all +ve labeled by our program (whether they’re diabetic or not in reality).

Recall (aka Sensitivity)

Recall is the ratio of the correctly +ve labeled by our program to all who are diabetic in reality.
Recall answers the following question: Of all the people who are diabetic, how many of those we correctly predict?
Recall = TP/(TP+FN)
numerator: +ve labeled diabetic people.
denominator: all people who are diabetic (whether detected by our program or not)

F1-score (aka F-Score / F-Measure)

F1 Score considers both precision and recall.
It is the harmonic mean(average) of the precision and recall.
F1 Score is best if there is some sort of balance between precision (p) & recall (r) in the system. Oppositely F1 Score isn’t so high if one measure is improved at the expense of the other.
For example, if P is 1 & R is 0, F1 score is 0.
F1 Score = 2*(Recall * Precision) / (Recall + Precision)

Specificity

Specificity is the correctly -ve labeled by the program to all who are healthy in reality.
Specifity answers the following question: Of all the people who are healthy, how many of those did we correctly predict?
Specificity = TN/(TN+FP)
numerator: -ve labeled healthy people.
denominator: all people who are healthy in reality (whether +ve or -ve labeled)

General Notes

Yes, accuracy is a great measure but only when you have symmetric datasets (false negatives & false positives counts are close), also, false negatives & false positives have similar costs.
If the cost of false positives and false negatives are different then F1 is your savior. F1 is best if you have an uneven class distribution.

Precision is how sure you are of your true positives whilst recall is how sure you are that you are not missing any positives.

Choose Recall if the idea of false positives is far better than false negatives, in other words, if the occurrence of false negatives is unaccepted/intolerable, that you’d rather get some extra false positives(false alarms) over saving some false negatives, like in our diabetes example.
You’d rather get some healthy people labeled diabetic over leaving a diabetic person labeled healthy.

Choose precision if you want to be more confident of your true positives. for example, Spam emails. You’d rather have some spam emails in your inbox rather than some regular emails in your spam box. So, the email company wants to be extra sure that email Y is spam before they put it in the spam box and you never get to see it.

Choose Specificity if you want to cover all true negatives, meaning you don’t want any false alarms, you don’t want any false positives. for example, you’re running a drug test in which all people who test positive will immediately go to jail, you don’t want anyone drug-free going to jail. False positives here are intolerable.

Bottom Line is

— Accuracy value of 90% means that 1 of every 10 labels is incorrect, and 9 is correct.
— Precision value of 80% means that on average, 2 of every 10 diabetic labeled student by our program is healthy, and 8 is diabetic.
— Recall value is 70% means that 3 of every 10 diabetic people in reality are missed by our program and 7 labeled as diabetic.
— Specificity value is 60% means that 4 of every 10 healthy people in reality are miss-labeled as diabetic and 6 are correctly labeled as healthy.

Confusion Matrix

Wikipedia will explain it better than me

In the field of machine learning and specifically the problem of statistical classification, a confusion matrix, also known as an error matrix, is a specific table layout that allows visualization of the performance of an algorithm, typically a supervised learning one (in unsupervised learning it is usually called a matching matrix). Each row of the matrix represents the instances in a predicted class while each column represents the instances in an actual class (or vice versa).The name stems from the fact that it makes it easy to see if the system is confusing two classes (i.e. commonly mislabeling one as another).

A nice & easy how-to of calculating a confusion matrix is here.

from sklearn.metrics import confusion_matrix
>>>tn, fp, fn, tp = confusion_matrix([0, 1, 0, 1],
[1, 1, 1, 0]).ravel()
# true negatives, false positives, false negatives, true positives
>>>(tn, fp, fn, tp)

(0, 2, 1, 1) 

댓글 없음:

댓글 쓰기

태그

2025년 가열재생방식 가치기반 가치기반학습 가치이터레이션 강화학습 강화학습기초이론 강화학습방법 강화학습종류 개나리 개념 개발업무 최적화 건강 건식전극코팅 검사 검사기 검사장비 검사장비 양산라인 투입 절차 검색엔진최적화 검색키워드 검출율 경쟁력 경험재플레이 고체전해질적용 공부방법 공정간 에너지 흐름 공정내 에너지 절감 기술 과검율 관절 구글검색키워드 군마트 극초박형 셀제조 기계학습 기내반입 기대값 기초용어 나스닥 남녀사랑 냉각시스템 네이버 네이버 검색 키워드 분석 단백질 답변거부능력 더 원씽 덕담 동적계획법 듀얼브레인 드로스 딥시크 레이저노칭 문제점 로봇산업 롤투롤 생산공정 리액트히터 리튬산업 마르코프과정 마르코프의사결정 막걸리 말을 잘하는 방법 멀티 스텝 모델링 메모리 메인내용 메주콩 메주콩파종 멧돌호박 모델기반학습 모델종류 모델프리학습 모듈 모바일 몬테카를로 방법 몬테카를로방법 물류 및 공급망 최적화 물성의 성질 미국 오하이오 미국주가 미국주식 미래기술전망 미래전망 미세플라스틱 미중경쟁 밀도범함수이론 반도체 가격 상승 반사율 방수 배터리 배터리 주요불량 배터리공정 배터리기술 배터리불량 배터리소재 배터리신뢰성 배터리와인공지능 배터리정책 배터리제조 배터리제조신기술 백주 뱀때 버거체인 벨만방정식 병역명문가 보조배터리 보조배터리 기내반입 분석솔루션 불량원인분석 비례적분미분제어 비전 비지도학습 사랑 삼성반도체 새피해 새해인사 새해인사말 생각정리 생각정리기술 생마늘 생산계획 생수 생수페트병 설계최적화 설날인사말 설비고장예측 성심당 성심당온라인 구매 성심당추천빵 셀 스웰링 셀스웰링 셀투팩 소매업 소재개발 소프트뱅크 쇠뜨기 수명예측 수요예측 스마트팩토리 스웰링불량 시간차학습 시계열분석 시뮬레이션 신뢰성 액터-크리틱 양배추 양자컴퓨터 어텐션 어텐션메커니즘 에너지 절감 에너지 절감방법 에너지사용최적화 에너지절감 에너지절감방안 에어드라이어 에피소드 기반 학습 엘지전자 영어 영어 리스닝 예제 오버행불량 오버행불량원인 오프폴리시 온누리상품권 온폴리시 용접 워런버핏 원달러 변화패턴 원달러 환율전망 원엔환율 원인 원자간 상호작용 학습 및 예측 웬디스버거 을사 인간피드백을 통한 강화학습 인공지능 인공지능경쟁 인생 일본금리 일본환율 자발적DR 자이가르닉 효과 장마 재고관리 재생시스템 재활용소재활용 저전압 저축 전자분포 전자의 움직임 전자의분포 전자의움직임 전통시장통통 정식방법 정책기반 정책기반 이터레이션 정책기반학습 정책이터레이션 제사상 제습공조설비 제습효율 제조업 제조에너지절감 제품개발 젠슨황 조합최적화 주식 중국공급과잉 중요샘플링 지도학습 지도학습미세조정 지붕방수 지수평활법 창신메모리테크놀로지 책줄거리 청주 최신배터리기술 최신이슈 최적제어 추정 추천빵 코스모스 콜드 스타트 키워드 분석 탁주 통계적 방법 투자 투자가 투자철학 트럼프2.0 트루시니스 파종 패키징공정 페트병 페트병두께 푸른뱀때 품질관리 피엑스 필요기술 필요지식 하이닉스 학습항목 한국반도체 행복 행위적인공지능 현대차 화합물 물성 확률 효능 효율적인 업무방법 휴머노이드로봇 흡착식 에너 드라이어 흡착식에어드라이어 흡착제 힘의교환 Actor Actor-Critic 강화학습 Actor-Critic학습 Agentic AI AI AI기반품질관리 Air Dryer ARIMA AS재고관리 Attention Attention Algorithm Battery Manufacturing Battery Manufaturing Battery Material Books Books for Beginners to Learn About LLM CATL Cell to Pack confusion matrix Critic CTC CTP CXMT DDR5 Deep Learning Deep Seek DeepSeek Demand Response DFT DIO Double DQN DP DPO DQN Dross DSO Dueling DQN dumplings Dynamic Programming ESS ESS솔루션 EV FFC FFC체결여부 검사 garlic genesis Gongi Graph Enhanced RAG Health Horsetail Hot Areas how to speak well Human Feedback importance sampling Kitchen hoods Korean dumplings Korean Rice Cake Soup Korean Traditional Game Large Language Models LLM LSTM Machine Learning Interatomic Potential Mandy Material Development MDP MLIP MMFF94 Multi-step Modeling New Battery Materials NMP Recovery Nuts PCU Physical AI PID제어 ppm PPO Pre Cooling Unit pre training Precooling Unit Prophet Protein Q-Learning Quality Inspection Data Quality Management RAG Raw Garlic RCU React Heater REINFORCE REINFORCE학습 Reinforcement Learning Reliability Return cooling Unit RL RLHF RORL RUL방법 SARIMA SARSA SCM SCM 핵심 재무 지표 SEO SFT SHAP SHAP로직 small kitchen hoods squd Squid Game Stacking TD학습 Temporal Difference Tener Stack Time Difference Learning truthiness Ttakji Tteokguk VAR ventilations for small spaces Vision Water Z-Stacking