■ Precision-Recall Graph 그리기

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

import matplotlib.pyplot as pp

import numpy as np

import sklearn.metrics as metrics

 

modelAClassValueNDArray       = np.array([0   , 0   , 0   , 0   , 0   , 0   , 1   , 0   , 1   , 1   , 0   , 0   , 0   , 1   , 1   ])

modelAClassProbabilityNDArray = np.array([0.05, 0.05, 0.15, 0.15, 0.25, 0.25, 0.35, 0.35, 0.45, 0.45, 0.55, 0.55, 0.65, 0.85, 0.95])

 

modelBClassValueNDArray       = np.array([0   , 0   , 0   , 1   , 1   , 0   , 0   , 1   , 0   , 0   , 1   , 0   , 0   , 0   , 1   ])

modelBClassProbabilityNDArray = np.array([0.05, 0.05, 0.15, 0.15, 0.25, 0.25, 0.25, 0.35, 0.35, 0.45, 0.55, 0.55, 0.65, 0.75, 0.95])

 

modelAPrecisionNDArray, modelARecallRateNDArray, _ = metrics.precision_recall_curve(modelAClassValueNDArray, modelAClassProbabilityNDArray)

modelBPrecisionNDArray, modelBRecallRateNDArray, _ = metrics.precision_recall_curve(modelBClassValueNDArray, modelBClassProbabilityNDArray)

 

modelAAP = metrics.average_precision_score(modelAClassValueNDArray, modelAClassProbabilityNDArray)

modelBAP = metrics.average_precision_score(modelBClassValueNDArray, modelBClassProbabilityNDArray)

 

pp.title("Precision-Recall Graph")

 

pp.xlabel("Recall"   )

pp.ylabel("Precision")

 

pp.plot(modelARecallRateNDArray, modelAPrecisionNDArray, "b", label = "Model A (AP = %0.2F)" % modelAAP)

pp.plot(modelBRecallRateNDArray, modelBPrecisionNDArray, "g", label = "Model B (AP = %0.2F)" % modelBAP)

 

pp.legend(loc = "upper right")

 

pp.show()

 

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

Posted by 사용자 icodebroker