집합 {0,1}에 이진 관측치가 있다고 가정합니다.
당신은 [0, 1] 로짓 함수를 사용하여 범위에 근사한 변수의 예측 값을 변환 할 수 있습니다
phat_new = exp(phat)/(1+exp(phat))
지금, 당신이 알고 무엇 예측값, phat_new, 관찰의 진정한 가치, val_y_matrix, 귀하의 유효성 확인 데이터 세트 p의 1의 백분율이 있습니다. ROC을 플로팅하는 한 가지 방법은 다음과 같습니다.
fix t. 이것은 모델에 대한 컷오프 임계 값 ([0,1] 단위)입니다. 다음을 계산하십시오.
# percentage of 1 observations in the validation set,
p = length(which(val_y_matrix==1))/length(val_y_matrix)
# probability of the model predicting 1 while the true value of the observation is 0,
p_01 = sum(1*(phat_new>=t & val_y_matrix==0))/dim(val_x_matrix)[1]
# probability of the model predicting 1 when the true value of the observation is 1,
p_11 = sum(1*(phat_new>=t & val_y_matrix==1))/dim(val_x_matrix)[1]
# probability of false-positive,
p_fp = p_01/(1-p)
# probability of true-positive,
p_tp = p_11/p
# plot the ROC,
plot(p_fp, p_tp)
이 방법을 사용하는 것이 더 좋은지 궁금합니다. 예를 들어 분류 트리를 사용하는 경우 손실 매트릭스를 모델의 입력으로 제공 할 수 있으며 손실 매트릭스의 비용 비율에 따라 얻을 수있는 모델이 달라집니다. 즉, 비용 비율을 변경하면 다른 모델을 얻게되며 다른 모델은 ROC 곡선에서 다른 점이됩니다.
않습'ROCR' 패키지 작업을 확인? 그렇지 않은 경우 특정 문제가 무엇입니까? – smci