🤖 AI/ML

Accuracy

Accuracy

The proportion of correct predictions. The basic evaluation metric for classification problems. Requires caution with imbalanced data.

📖 Detailed Explanation

Accuracy is the most basic evaluation metric for classification models, representing the proportion of all predictions that are correct. Mathematically it is calculated as (TP + TN) / (TP + TN + FP + FN), where TP means True Positive, TN True Negative, FP False Positive, and FN False Negative.

Accuracy is the oldest and most intuitive metric in the history of machine learning and has long been used as the basic evaluation method for classification problems. However, as imbalanced-dataset problems in areas such as medical diagnosis and fraud detection came to the fore in the 1990s, it became widely recognized that accuracy alone cannot properly evaluate model performance. Complementary metrics such as Precision, Recall, F1-Score, and AUC-ROC were developed afterward.

The key limitation of accuracy arises with class imbalance. For example, in a dataset where 1% of patients have cancer, predicting "everyone is healthy" gives 99% accuracy, but the model is actually useless. Conversely, on balanced datasets (for example, MNIST and CIFAR-10), accuracy is still a useful metric. Therefore, you should first check the data distribution and choose an appropriate metric.

As of 2025, it is rare in practice to use accuracy alone. In Kaggle and AI competitions, AUC-ROC, Log Loss, and F1-Score are the main evaluation metrics, and in LLM evaluation, domain-specific metrics such as BLEU, ROUGE, and human evaluation are central. Even so, accuracy is still useful for quick sanity checks and for comparing models.

💻 Code Example

Example of computing various classification metrics alongside accuracy:

# 정확도 및 분류 평가 지표 계산
from sklearn.metrics import (
    accuracy_score, precision_score, recall_score,
    f1_score, classification_report, confusion_matrix
)
import numpy as np

# 예시 데이터: 이진 분류 결과
y_true = [1, 0, 1, 1, 0, 1, 0, 0, 1, 1]  # 실제 레이블
y_pred = [1, 0, 1, 0, 0, 1, 1, 0, 1, 0]  # 예측 레이블

# 1. 정확도 (Accuracy)
accuracy = accuracy_score(y_true, y_pred)
print(f"정확도: {accuracy:.2%}")  # 70.00%

# 2. 정밀도 (Precision) - 예측 양성 중 실제 양성 비율
precision = precision_score(y_true, y_pred)
print(f"정밀도: {precision:.2%}")  # 80.00%

# 3. 재현율 (Recall) - 실제 양성 중 예측 양성 비율
recall = recall_score(y_true, y_pred)
print(f"재현율: {recall:.2%}")  # 66.67%

# 4. F1-Score - 정밀도와 재현율의 조화평균
f1 = f1_score(y_true, y_pred)
print(f"F1-Score: {f1:.2%}")  # 72.73%

# 5. 혼동 행렬 (Confusion Matrix)
cm = confusion_matrix(y_true, y_pred)
print("\n혼동 행렬:")
print(f"  TN={cm[0,0]}, FP={cm[0,1]}")
print(f"  FN={cm[1,0]}, TP={cm[1,1]}")

# 6. 전체 분류 리포트
print("\n상세 리포트:")
print(classification_report(y_true, y_pred, target_names=['음성', '양성']))

Simulating the accuracy problem with imbalanced data:

# 불균형 데이터에서 정확도의 함정
import numpy as np
from sklearn.metrics import accuracy_score, f1_score, balanced_accuracy_score

# 극단적 불균형: 양성 2%, 음성 98%
np.random.seed(42)
n_samples = 1000
n_positive = 20  # 2%

y_true = np.array([1] * n_positive + [0] * (n_samples - n_positive))

# 모델 A: 모든 것을 음성으로 예측 (단순 모델)
y_pred_naive = np.zeros(n_samples)

# 모델 B: 실제로 양성을 어느 정도 탐지하는 모델
y_pred_better = np.zeros(n_samples)
y_pred_better[:15] = 1  # 양성 15개 올바르게 예측
y_pred_better[25:30] = 1  # 오탐 5개

print("=== 불균형 데이터 (양성 2%) ===")
print(f"\n[모델 A: 전부 음성 예측]")
print(f"  정확도: {accuracy_score(y_true, y_pred_naive):.2%}")  # 98%!
print(f"  F1-Score: {f1_score(y_true, y_pred_naive):.2%}")  # 0%
print(f"  Balanced Accuracy: {balanced_accuracy_score(y_true, y_pred_naive):.2%}")

print(f"\n[모델 B: 양성 탐지 시도]")
print(f"  정확도: {accuracy_score(y_true, y_pred_better):.2%}")  # 99%
print(f"  F1-Score: {f1_score(y_true, y_pred_better):.2%}")  # 75%
print(f"  Balanced Accuracy: {balanced_accuracy_score(y_true, y_pred_better):.2%}")

print("\n=> 정확도만 보면 두 모델이 비슷해 보이지만, F1은 완전히 다름!")

📊 Performance Metric Comparison

Guide to choosing the right evaluation metric by situation:

Situation Recommended Metric Accuracy Suitability Reason
Balanced data (50:50) Accuracy, F1 Suitable Class distribution is balanced
Imbalanced data (95:5) F1, AUC-ROC Unsuitable Majority-class bias
Medical diagnosis (must not miss cases) Recall, Sensitivity Unsuitable Minimizing FN is important
Spam filter (minimize false positives) Precision Supplementary Minimizing FP is important
Multi-class classification Macro F1, Weighted F1 For reference Per-class balanced evaluation

🗣️ Say It Like This in Practice

💬 In a Meeting
"You said accuracy is 98%, but what percentage of the data is the positive class? If the data is imbalanced, I think we should also look at F1-Score or AUC-ROC."
💬 In an Interview
"When the positive class is rare, as in fraud detection, the Precision-Recall curve or F1-Score is more suitable than accuracy. Depending on business requirements, you have to decide whether to put more weight on Precision or Recall."
💬 In a Technical Discussion
"Accuracy is fine on balanced datasets like MNIST, but if the data distribution in the real deployment environment is different, performance can drop sharply. Before deployment, you must re-evaluate on data with the real distribution."

Take a mock interview on this topic → WIA SOOM AI Interview · Start for free

⚠️ Common Mistakes & Cautions

❌

Choosing a model based on accuracy alone

On imbalanced data, a model with 99% accuracy may actually fail to detect the minority class at all. Always check the confusion matrix and per-class metrics together.

❌

Not checking the test data distribution

If the class distributions of the training and test data differ, accuracy is distorted. Be especially careful about distribution changes over time (Data Drift) in time-series data.

✅

The right approach

First check the data distribution and choose a metric that fits your business goal. Use a metric suited to the situation, such as Balanced Accuracy, F1-Score, or AUC-ROC, as the primary metric, and use accuracy as a secondary metric.

🔗 Related Terms

📚 Learn More