수색…


ROC 및 AUC 소개

분류 자 출력 품질을 평가하는 수신자 작동 특성 (ROC) 측정 기준의 예.

ROC 곡선은 일반적으로 Y 축의 진정한 양의 비율과 X 축의 잘못된 양의 비율을 나타냅니다. 이것은 플롯의 좌상단이 "이상적인"지점이라는 것을 의미합니다. 오탐 (false positive rate)은 0이고, 진정한 양의 비율은 1입니다. 이는 사실적이지는 않지만 커브 아래의 더 넓은 영역 (AUC)이 일반적으로 더 좋다는 것을 의미합니다.

거짓 긍정 (false positive) 비율을 최소화하면서 진정한 양의 비율을 최대화하는 것이 이상적이기 때문에 ROC 곡선의 "가파른 부분"도 중요합니다.

간단한 예 :

import numpy as np
from sklearn import metrics
import matplotlib.pyplot as plt

임의의 y 값 - 실제 값은 예측 된 목표 값 ( model.predict(x_test) )입니다.

y = np.array([1,1,2,2,3,3,4,4,2,3])

점수는 주어진 테스트 데이터 및 레이블의 평균 정확도입니다 ( model.score(X,Y) ).

scores = np.array([0.3, 0.4, 0.95,0.78,0.8,0.64,0.86,0.81,0.9, 0.8])

ROC 곡선과 AUC를 계산하십시오 :

fpr, tpr, thresholds = metrics.roc_curve(y, scores, pos_label=2)
roc_auc = metrics.auc(fpr, tpr)

플로팅 :

plt.figure()
plt.plot(fpr, tpr, label='ROC curve (area = %0.2f)' % roc_auc)
plt.plot([0, 1], [0, 1], 'k--')
plt.xlim([0.0, 1.0])
plt.ylim([0.0, 1.05])
plt.xlabel('False Positive Rate')
plt.ylabel('True Positive Rate')
plt.title('Receiver operating characteristic example')
plt.legend(loc="lower right")
plt.show()

산출:

여기에 이미지 설명을 입력하십시오.

참고 : 소스는이 link1link2 에서 가져 왔습니다.

오버라이드 및 교차 검증을 통한 ROC-AUC 점수

ROC-AUC (곡선 아래 영역) 점수를 계산하기 위해 예측 된 확률이 필요합니다. cross_val_predict 는 분류 자의 predict 방법을 사용합니다. ROC-AUC 점수를 얻으려면 분류 메소드를 서브 클래스로 분류하여 predict 메소드를 재정 의하여 predict_proba 와 같은 predict_proba 합니다.

from sklearn.datasets import make_classification
from sklearn.linear_model import LogisticRegression
from sklearn.cross_validation import cross_val_predict
from sklearn.metrics import roc_auc_score

class LogisticRegressionWrapper(LogisticRegression):
    def predict(self, X):
        return super(LogisticRegressionWrapper, self).predict_proba(X)

X, y = make_classification(n_samples = 1000, n_features=10, n_classes = 2, flip_y = 0.5)

log_reg_clf = LogisticRegressionWrapper(C=0.1, class_weight=None, dual=False,
             fit_intercept=True)

y_hat = cross_val_predict(log_reg_clf, X, y)[:,1]

print("ROC-AUC score: {}".format(roc_auc_score(y, y_hat)))

산출:

ROC-AUC score: 0.724972396025


Modified text is an extract of the original Stack Overflow Documentation
아래 라이선스 CC BY-SA 3.0
와 제휴하지 않음 Stack Overflow