AUC-ROC
Area Under ROC Curve
A performance metric for binary classification models. Visualizes the trade-off between TPR and FPR.
Area Under ROC Curve
A performance metric for binary classification models. Visualizes the trade-off between TPR and FPR.
AUC-ROC (Area Under the ROC Curve) is a key metric for evaluating the performance of binary classification models. The ROC curve is a graph that visualizes the relationship between the True Positive Rate (TPR, sensitivity) and the False Positive Rate (FPR, 1 - specificity) as the classification threshold varies from 0 to 1, and AUC is the value calculated as the area under this curve.
The ROC curve was developed in the 1940s, during World War II, for detecting radar signals. It later spread to various fields such as medical diagnosis, credit scoring, and fraud detection, and it has now become established as a standard metric for evaluating machine learning models.
AUC values range from 0 to 1, where 0.5 means random guessing and 1.0 means perfect classification. In practice, a model is evaluated as acceptable if its AUC is 0.7 or higher, excellent if 0.8 or higher, and outstanding if 0.9 or higher. A key advantage of AUC is that it is threshold-independent, which allows stable evaluation even on class-imbalanced data.
In financial fraud detection, the target is an AUC of 0.95 or higher, and in medical diagnosis AI, 0.85 or higher is the basic requirement for FDA approval. In marketing campaign targeting, even an AUC of 0.75 can be expected to deliver significant cost savings, so setting an appropriate target value according to the domain is important.
from sklearn.datasets import make_classification
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import roc_auc_score, roc_curve
import matplotlib.pyplot as plt
# 샘플 데이터 생성
X, y = make_classification(n_samples=1000, n_classes=2,
n_features=20, random_state=42)
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.3, random_state=42)
# 모델 학습
model = LogisticRegression()
model.fit(X_train, y_train)
# 예측 확률 (AUC 계산에는 확률값 필요)
y_pred_proba = model.predict_proba(X_test)[:, 1]
# AUC-ROC 계산
auc_score = roc_auc_score(y_test, y_pred_proba)
print(f"AUC-ROC Score: {auc_score:.4f}")
# ROC 곡선 그리기
fpr, tpr, thresholds = roc_curve(y_test, y_pred_proba)
plt.figure(figsize=(8, 6))
plt.plot(fpr, tpr, label=f'ROC Curve (AUC = {auc_score:.3f})')
plt.plot([0, 1], [0, 1], 'k--', label='Random Guess')
plt.xlabel('False Positive Rate')
plt.ylabel('True Positive Rate')
plt.title('ROC Curve')
plt.legend()
plt.grid(True, alpha=0.3)
plt.show()
"The AUC of this fraud detection model is 0.92, an improvement of 0.05 over the previous model. However, since the class imbalance is 99:1, I think we should look at PR-AUC as well."
"Please explain the difference between AUC-ROC and Accuracy. If Accuracy is 95% but AUC is 0.6 on data with severe class imbalance, what kind of problem is that?"
"You need to pass predict_proba instead of the predict result to roc_auc_score. AUC isn't calculated accurately with 0/1 binary values."
Take a mock interview on this topic → WIA SOOM AI Interview · Start for free
You must use probability values (predict_proba) when calculating AUC. If you pass binary predictions (0/1), they cannot reflect changes in the threshold, producing an inaccurate AUC.
Under extreme class imbalance (1:100 or more), AUC-ROC alone is not enough. Check PR-AUC (Precision-Recall AUC) as well to accurately understand the model's performance on the positive class.
For multiclass problems, AUC must be calculated using the One-vs-Rest or One-vs-One approach. Use sklearn's multi_class='ovr' or 'ovo' option.