예제 #1
0
def plotPRC(output, LTE, figure_fname = "", prc_label = 'PRC'):
    """Plots a precision recall curve into the supplied
    figure_fname file"""
    from matplotlib import use
    use("Agg")  # matplotlib save without display
    from pylab import figure, plot, axis, xticks, yticks, ylabel, xlabel, legend, savefig

    figure(2, dpi = 150, figsize = (4, 4))

    pm = PerformanceMeasures(Labels(numpy.array(LTE)), Labels(numpy.array(output)))

    points = pm.get_PRC()
    points = numpy.array(points).T # for pylab.plot
    plot(points[0], points[1], 'b-', label = prc_label)
    axis([0, 1, 0, 1])
    ticks = numpy.arange(0., 1., .1, dtype = numpy.float64)
    xticks(ticks, size = 10)
    yticks(ticks, size = 10)
    xlabel('sensitivity (true positive rate)', size = 10)
    ylabel('precision (1 - false discovery rate)', size = 10)
    legend(loc = 'lower right')
    
    if figure_fname != None:
        warnings.filterwarnings('ignore', 'Could not match*')
        tempfname = figure_fname + '.png'
    savefig(tempfname)
    shutil.move(tempfname, figure_fname)
    
    auPRC = pm.get_auPRC()
    return auPRC 
예제 #2
0
def plotROC(output, LTE, draw_random = False, figure_fname = "", roc_label = 'ROC'):
    """Uses matplotlib to plot the area under 
    the ROC curve into a supplied figure_fname file"""
    from matplotlib import use, font_manager
    use("Agg")  # matplotlib save without display
    from pylab import figure, plot, xticks, yticks, xlabel, ylabel, legend, savefig, axis
    
    figure(1, dpi = 150, figsize = (4, 4))

    pm = PerformanceMeasures(Labels(numpy.array(LTE)), Labels(numpy.array(output)))

    points = pm.get_ROC()
    points = numpy.array(points).T # for pylab.plot
    plot(points[0], points[1], 'b-', label = roc_label)
    if draw_random:
        plot([0, 1], [0, 1], 'r-', label = 'random guessing')
    axis([0, 1, 0, 1])
    ticks = numpy.arange(0., 1., .1, dtype = numpy.float64)
    xticks(ticks, size = 10)
    yticks(ticks, size = 10)
    xlabel('1 - specificity (false positive rate)', size = 10)
    ylabel('sensitivity (true positive rate)', size = 10)
    legend(loc = 'lower right', prop = font_manager.FontProperties('tiny')) 

    if figure_fname != None:
        warnings.filterwarnings('ignore', 'Could not match*')
        tempfname = figure_fname + '.png'
    savefig(tempfname)
    shutil.move(tempfname, figure_fname)
    
    auROC = pm.get_auROC()
    return auROC
예제 #3
0
def calcPRC(output, LTE):
    """Uses shogun functions to calculate the precision recall curve"""
    pm = PerformanceMeasures(Labels(numpy.array(LTE)), Labels(numpy.array(output)))

    auPRC = pm.get_auPRC()
    return auPRC
예제 #4
0
def calcROC(output, LTE):
    """Uses shogun functions to calculate the area under the ROC curve"""
    pm = PerformanceMeasures(Labels(numpy.array(LTE)), Labels(numpy.array(output)))

    auROC = pm.get_auROC()
    return auROC