示例#1
0
    def run_real(self):
        """Runs the main application"""
        # Get the type of the curve to be plotted
        try:
            self.curve_class = CurveFactory.find_class_by_name(self.options.curve_type)
        except ValueError:
            self.parser.error("Unsupported curve type: %s" % self.options.curve_type)

        self.process_input_files()
        self.run_tests()
示例#2
0
文件: auc.py 项目: ashish01/yard
    def add_parser_options(self):
        """Creates the command line parser object for the application"""
        super(AUCCalculatorApplication, self).add_parser_options()

        parser = self.parser

        parser.add_option("-t", "--curve-type", dest="curve_types",
                metavar="TYPE", choices=CurveFactory.get_curve_names(),
                action="append", default=[],
                help="sets the TYPE of the curve to be plotted "
                     "(roc, pr, ac, sespe or croc). May be specified "
                     "multiple times.")
示例#3
0
文件: auc.py 项目: IanMadlenya/yard
    def add_parser_options(self):
        """Creates the command line parser object for the application"""
        super(AUCCalculatorApplication, self).add_parser_options()

        parser = self.parser

        parser.add_option("-t",
                          "--curve-type",
                          dest="curve_types",
                          metavar="TYPE",
                          choices=CurveFactory.get_curve_names(),
                          action="append",
                          default=[],
                          help="sets the TYPE of the curve to be plotted "
                          "(roc, pr, ac, sespe or croc). May be specified "
                          "multiple times.")
示例#4
0
文件: auc.py 项目: IanMadlenya/yard
    def run_real(self):
        """Runs the main application"""

        # If no curve type was given, assume a ROC curve
        if not self.options.curve_types:
            self.options.curve_types = ["roc"]

        # Get the types of the curves to be plotted
        curve_classes = []
        for name in self.options.curve_types:
            try:
                curve_classes.append(CurveFactory.find_class_by_name(name))
            except ValueError:
                self.parser.error("Unknown curve type: %s" % name)

        self.process_input_files()
        for curve_class in curve_classes:
            self.print_scores_for_curve(curve_class)
示例#5
0
文件: auc.py 项目: ashish01/yard
    def run_real(self):
        """Runs the main application"""

        # If no curve type was given, assume a ROC curve
        if not self.options.curve_types:
            self.options.curve_types = ["roc"]

        # Get the types of the curves to be plotted
        curve_classes = []
        for name in self.options.curve_types:
            try:
                curve_classes.append(CurveFactory.find_class_by_name(name))
            except ValueError:
                self.parser.error("Unknown curve type: %s" % name)

        self.process_input_files()
        for curve_class in curve_classes:
            self.print_scores_for_curve(curve_class)
示例#6
0
文件: plot.py 项目: ntamas/yard
    def add_parser_options(self):
        """Creates the command line parser object for the application"""
        super(ROCPlotterApplication, self).add_parser_options()

        parser = self.parser

        parser.add_option("-t", "--curve-type", dest="curve_types",
                metavar="TYPE", choices=CurveFactory.get_curve_names(),
                action="append", default=[],
                help="sets the TYPE of the curve to be plotted "
                     "(roc, pr, ac, sespe or croc). May be specified "
                     "multiple times.")
        parser.add_option("-l", "--log-scale", dest="log_scale",
                metavar="AXES",
                help="use logarithmic scale on the given AXES. "
                     "Valid values: none, x, y and xy",
                choices=["none", "x", "y", "xy"], default="none")
        parser.add_option("-o", "--output", dest="output", metavar="FILE",
                help="saves the plot to the given FILE instead of showing it",
                default=None)
        parser.add_option("-s", "--size", dest="size", metavar="WIDTHxHEIGHT",
                help="sets the size of the figure to WIDTHxHEIGHT, where "
                     "WIDTH and HEIGHT are measures in inches. You may "
                     "specify alternative measures (cm or mm) by adding "
                     "them as a suffix; e.g., \"6cmx4cm\" or \"6cm x 4cm\"",
                 default=None)
        parser.add_option("--dpi", dest="dpi", metavar="DPI",
                type=float, default=72.0,
                help="specifies the dpi value (dots per inch) when "
                     "converting pixels to inches and vice versa "
                     "in figure and font size calculations. "
                     "Default: %default")
        parser.add_option("--font-size", dest="font_size", metavar="SIZE",
                type=float, default=None,
                help="overrides the font size to be used on figures, "
                     "in points (pt).")
        parser.add_option("--show-auc", dest="show_auc", action="store_true",
                default=False, help="shows the AUC scores in the legend")
        parser.add_option("--no-resampling", dest="resampling", action="store_false",
                default=True, help="don't resample curves before "
                                   "plotting and AUC calculation")
示例#7
0
文件: plot.py 项目: ntamas/yard
    def run_real(self):
        """Runs the main application"""
        import matplotlib

        # Do we need headless mode for matplotlib?
        if self.options.output:
            matplotlib.use("agg")

        # If no curve type was given, assume a ROC curve
        if not self.options.curve_types:
            self.options.curve_types = ["roc"]

        # Set up the font size
        if self.options.font_size is not None:
            for param in ['font.size', 'legend.fontsize']:
                matplotlib.rcParams[param] = self.options.font_size

        # Get the types of the curves to be plotted
        curve_classes = []
        for name in self.options.curve_types:
            try:
                curve_classes.append(CurveFactory.find_class_by_name(name))
            except ValueError:
                self.parser.error("Unknown curve type: %s" % name)

        # Do we have multiple curve types? If so, we need PDF output
        pp = None
        if len(curve_classes) > 1:
            if not self.options.output or \
               not self.options.output.endswith(".pdf"):
                self.parser.error("multiple curves can only be plotted to PDF")

            try:
                from matplotlib.backends.backend_pdf import PdfPages
            except ImportError:
                self.parser.error("Matplotlib is too old and does not have "
                        "multi-page PDF support yet. Please upgrade it to "
                        "Matplotlib 0.99 or later")

            pp = PdfPages(self.options.output)
            def figure_saver(figure):
                pp.savefig(figure, bbox_inches="tight")
        elif self.options.output:
            # Figure with a single plot will be created
            def figure_saver(figure):
                self.log.info("Saving plot to %s..." % self.options.output)
                figure.savefig(self.options.output, bbox_inches="tight")
        else:
            # Figure will be shown on screen
            def figure_saver(figure):
                import matplotlib.pyplot as plt
                plt.show()

        self.process_input_files()

        self.log.info("Plotting results...")
        for curve_class in curve_classes:
            fig = self.get_figure_for_curves(curve_class)
            figure_saver(fig)

        # For multi-page output, we have to close it explicitly
        if pp is not None:
            pp.close()
示例#8
0
文件: plot.py 项目: IanMadlenya/yard
    def add_parser_options(self):
        """Creates the command line parser object for the application"""
        super(ROCPlotterApplication, self).add_parser_options()

        parser = self.parser

        parser.add_option("-t",
                          "--curve-type",
                          dest="curve_types",
                          metavar="TYPE",
                          choices=CurveFactory.get_curve_names(),
                          action="append",
                          default=[],
                          help="sets the TYPE of the curve to be plotted "
                          "(roc, pr, ac, sespe or croc). May be specified "
                          "multiple times.")
        parser.add_option("-l",
                          "--log-scale",
                          dest="log_scale",
                          metavar="AXES",
                          help="use logarithmic scale on the given AXES. "
                          "Valid values: none, x, y and xy",
                          choices=["none", "x", "y", "xy"],
                          default="none")
        parser.add_option(
            "-o",
            "--output",
            dest="output",
            metavar="FILE",
            help="saves the plot to the given FILE instead of showing it",
            default=None)
        parser.add_option(
            "-s",
            "--size",
            dest="size",
            metavar="WIDTHxHEIGHT",
            help="sets the size of the figure to WIDTHxHEIGHT, where "
            "WIDTH and HEIGHT are measures in inches. You may "
            "specify alternative measures (cm or mm) by adding "
            "them as a suffix; e.g., \"6cmx4cm\" or \"6cm x 4cm\"",
            default=None)
        parser.add_option("--dpi",
                          dest="dpi",
                          metavar="DPI",
                          type=float,
                          default=72.0,
                          help="specifies the dpi value (dots per inch) when "
                          "converting pixels to inches and vice versa "
                          "in figure and font size calculations. "
                          "Default: %default")
        parser.add_option(
            "--font-size",
            dest="font_size",
            metavar="SIZE",
            type=float,
            default=None,
            help="overrides the font size to be used on figures, "
            "in points (pt).")
        parser.add_option("--show-auc",
                          dest="show_auc",
                          action="store_true",
                          default=False,
                          help="shows the AUC scores in the legend")
        parser.add_option("--no-resampling",
                          dest="resampling",
                          action="store_false",
                          default=True,
                          help="don't resample curves before "
                          "plotting and AUC calculation")
示例#9
0
文件: plot.py 项目: IanMadlenya/yard
    def run_real(self):
        """Runs the main application"""
        import matplotlib

        # Do we need headless mode for matplotlib?
        if self.options.output:
            matplotlib.use("agg")

        # If no curve type was given, assume a ROC curve
        if not self.options.curve_types:
            self.options.curve_types = ["roc"]

        # Set up the font size
        if self.options.font_size is not None:
            for param in ['font.size', 'legend.fontsize']:
                matplotlib.rcParams[param] = self.options.font_size

        # Get the types of the curves to be plotted
        curve_classes = []
        for name in self.options.curve_types:
            try:
                curve_classes.append(CurveFactory.find_class_by_name(name))
            except ValueError:
                self.parser.error("Unknown curve type: %s" % name)

        # Do we have multiple curve types? If so, we need PDF output
        pp = None
        if len(curve_classes) > 1:
            if not self.options.output or \
               not self.options.output.endswith(".pdf"):
                self.parser.error("multiple curves can only be plotted to PDF")

            try:
                from matplotlib.backends.backend_pdf import PdfPages
            except ImportError:
                self.parser.error(
                    "Matplotlib is too old and does not have "
                    "multi-page PDF support yet. Please upgrade it to "
                    "Matplotlib 0.99 or later")

            pp = PdfPages(self.options.output)

            def figure_saver(figure):
                pp.savefig(figure, bbox_inches="tight")
        elif self.options.output:
            # Figure with a single plot will be created
            def figure_saver(figure):
                self.log.info("Saving plot to %s..." % self.options.output)
                figure.savefig(self.options.output, bbox_inches="tight")
        else:
            # Figure will be shown on screen
            def figure_saver(figure):
                import matplotlib.pyplot as plt
                plt.show()

        self.process_input_files()

        self.log.info("Plotting results...")
        for curve_class in curve_classes:
            fig = self.get_figure_for_curves(curve_class)
            figure_saver(fig)

        # For multi-page output, we have to close it explicitly
        if pp is not None:
            pp.close()