■ ROC(Receiver Operating Characteristic) Curve 그리기

----------------------------------------------------------------------------------------------------

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()

 

----------------------------------------------------------------------------------------------------

Posted by 사용자 icodebroker