■ ROC(Receiver Operating Characteristic) Curve를 그리는 방법을 보여준다.
▶ 예제 코드 (PY)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
import matplotlib.pyplot as pp import numpy as np import sklearn.metrics as metrics modelAClassValueNDArray = np.array([0 , 0 , 0 , 0 , 1 , 1 , 0 , 0 , 1 , 1 ]) modelAClassProbabilityNDArray = np.array([0.05, 0.15, 0.15, 0.25, 0.35, 0.45, 0.55, 0.65, 0.95, 0.95]) modelBClassValueNDArray = np.array([0 , 0 , 1 , 0 , 1 , 0 , 0 , 1 , 0 , 1 ]) modelBClassProbabilityNDArray = np.array([0.05, 0.05, 0.15, 0.25, 0.35, 0.45, 0.65, 0.75, 0.85, 0.95]) modelAFalsePositiveRate, modelATruePositiveRate, modelAThreshold = metrics.roc_curve(modelAClassValueNDArray, modelAClassProbabilityNDArray) modelBFalsePositiveRate, modelBTruePositiveRate, modelBThreshold = metrics.roc_curve(modelBClassValueNDArray, modelBClassProbabilityNDArray) modelAROCAUC = metrics.auc(modelAFalsePositiveRate, modelATruePositiveRate) modelBROCAUC = metrics.auc(modelBFalsePositiveRate, modelBTruePositiveRate) pp.title("Receiver Operating Characteristic") pp.xlabel("False Positive Rate(1 - Specificity)") pp.ylabel("True Positive Rate(Sensitivity)") pp.plot(modelAFalsePositiveRate, modelATruePositiveRate, "b", label = "Model A (AUC = %0.2f)" % modelAROCAUC) pp.plot(modelBFalsePositiveRate, modelBTruePositiveRate, "g", label = "Model B (AUC = %0.2f)" % modelBROCAUC) pp.plot([0, 1], [1, 1], "y--") pp.plot([0, 1], [0, 1], "r--") pp.legend(loc = "lower right") pp.show() |