Class AbstractOutput

  • All Implemented Interfaces:
    java.io.Serializable, OptionHandler
    Direct Known Subclasses:
    CSV, HTML, InMemory, Null, PlainText, XML

    public abstract class AbstractOutput
    extends java.lang.Object
    implements java.io.Serializable, OptionHandler
    A superclass for outputting the classifications of a classifier.

    Basic use with a classifier and a test set:

     Classifier classifier = ... // trained classifier
     Instances testset = ... // the test set to output the predictions for
     StringBuffer buffer = ... // the string buffer to add the output to
     AbstractOutput output = new FunkyOutput();
     output.setHeader(...);
     output.printClassifications(classifier, testset);
     
    Basic use with a classifier and a data source:
     Classifier classifier = ... // trained classifier
     DataSource testset = ... // the data source to obtain the test set from to output the predictions for
     StringBuffer buffer = ... // the string buffer to add the output to
     AbstractOutput output = new FunkyOutput();
     output.setHeader(...);
     output.printClassifications(classifier, testset);
     
    In order to make the output generation easily integrate into GUI components, one can output the header, classifications and footer separately:
     Classifier classifier = ... // trained classifier
     Instances testset = ... // the test set to output the predictions for
     StringBuffer buffer = ... // the string buffer to add the output to
     AbstractOutput output = new FunkyOutput();
     output.setHeader(...);
     // print the header
     output.printHeader();
     // print the classifications one-by-one
     for (int i = 0; i < testset.numInstances(); i++) {
       output.printClassification(classifier, testset.instance(i), i);
       // output progress information
       if ((i+1) % 100 == 0)
         System.out.println((i+1) + "/" + testset.numInstances());
     }
     // print the footer
     output.printFooter();
     
    Version:
    $Revision: 14069 $
    Author:
    fracpete (fracpete at waikato dot ac dot nz)
    See Also:
    Serialized Form
    • Constructor Detail

      • AbstractOutput

        public AbstractOutput()
        Initializes the output class.
    • Method Detail

      • globalInfo

        public abstract java.lang.String globalInfo()
        Returns a string describing the output generator.
        Returns:
        a description suitable for displaying in the GUI
      • getDisplay

        public abstract java.lang.String getDisplay()
        Returns a short display text, to be used in comboboxes.
        Returns:
        a short display text
      • listOptions

        public java.util.Enumeration<Option> listOptions()
        Returns an enumeration of all the available options..
        Specified by:
        listOptions in interface OptionHandler
        Returns:
        an enumeration of all available options.
      • setOptions

        public void setOptions​(java.lang.String[] options)
                        throws java.lang.Exception
        Sets the OptionHandler's options using the given list. All options will be set (or reset) during this call (i.e. incremental setting of options is not possible).
        Specified by:
        setOptions in interface OptionHandler
        Parameters:
        options - the list of options as an array of strings
        Throws:
        java.lang.Exception - if an option is not supported
      • getOptions

        public java.lang.String[] getOptions()
        Gets the current option settings for the OptionHandler.
        Specified by:
        getOptions in interface OptionHandler
        Returns:
        the list of current option settings as an array of strings
      • setHeader

        public void setHeader​(Instances value)
        Sets the header of the dataset.
        Parameters:
        value - the header
      • getHeader

        public Instances getHeader()
        Returns the header of the dataset.
        Returns:
        the header
      • setBuffer

        public void setBuffer​(java.lang.StringBuffer value)
        Sets the buffer to use.
        Parameters:
        value - the buffer
      • getBuffer

        public java.lang.StringBuffer getBuffer()
        Returns the current buffer.
        Returns:
        the buffer, can be null
      • setAttributes

        public void setAttributes​(java.lang.String value)
        Sets the range of attributes to output.
        Parameters:
        value - the range
      • getAttributes

        public java.lang.String getAttributes()
        Returns the range of attributes to output.
        Returns:
        the range
      • attributesTipText

        public java.lang.String attributesTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI
      • setOutputDistribution

        public void setOutputDistribution​(boolean value)
        Sets whether to output the class distribution or not.
        Parameters:
        value - true if the class distribution is to be output as well
      • getOutputDistribution

        public boolean getOutputDistribution()
        Returns whether to output the class distribution as well.
        Returns:
        true if the class distribution is output as well
      • outputDistributionTipText

        public java.lang.String outputDistributionTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI
      • getDefaultNumDecimals

        public int getDefaultNumDecimals()
        Returns the default number of digits to output after the decimal point.
        Returns:
        the default number of digits
      • setNumDecimals

        public void setNumDecimals​(int value)
        Sets the number of digits to output after the decimal point.
        Parameters:
        value - the number of digits
      • getNumDecimals

        public int getNumDecimals()
        Returns the number of digits to output after the decimal point.
        Returns:
        the number of digits
      • numDecimalsTipText

        public java.lang.String numDecimalsTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI
      • setOutputFile

        public void setOutputFile​(java.io.File value)
        Sets the output file to write to. A directory disables this feature.
        Parameters:
        value - the file to write to or a directory
      • getOutputFile

        public java.io.File getOutputFile()
        Returns the output file to write to. A directory if turned off.
        Returns:
        the file to write to or a directory
      • outputFileTipText

        public java.lang.String outputFileTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI
      • setSuppressOutput

        public void setSuppressOutput​(boolean value)
        Sets whether to the regular output is suppressed in case the output is stored in a file.
        Parameters:
        value - true if the regular output is to be suppressed
      • getSuppressOutput

        public boolean getSuppressOutput()
        Returns whether to the regular output is suppressed in case the output is stored in a file.
        Returns:
        true if the regular output is to be suppressed
      • suppressOutputTipText

        public java.lang.String suppressOutputTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI
      • generatesOutput

        public boolean generatesOutput()
        Returns whether regular output is generated or not.
        Returns:
        true if regular output is generated
      • printHeader

        public void printHeader()
        Prints the header to the buffer.
      • printClassification

        public void printClassification​(Classifier classifier,
                                        Instance inst,
                                        int index)
                                 throws java.lang.Exception
        Prints the classification to the buffer.
        Parameters:
        classifier - the classifier to use for printing the classification
        inst - the instance to print
        index - the index of the instance
        Throws:
        java.lang.Exception - if check fails or error occurs during printing of classification
      • printClassification

        public void printClassification​(double[] dist,
                                        Instance inst,
                                        int index)
                                 throws java.lang.Exception
        Prints the classification to the buffer.
        Parameters:
        dist - the distribution from classifier for the supplied instance
        inst - the instance to print
        index - the index of the instance
        Throws:
        java.lang.Exception - if check fails or error occurs during printing of classification
      • printClassifications

        public void printClassifications​(Classifier classifier,
                                         ConverterUtils.DataSource testset)
                                  throws java.lang.Exception
        Prints the classifications to the buffer.
        Parameters:
        classifier - the classifier to use for printing the classifications
        testset - the data source to obtain the test instances from
        Throws:
        java.lang.Exception - if check fails or error occurs during printing of classifications
      • printClassifications

        public void printClassifications​(Classifier classifier,
                                         Instances testset)
                                  throws java.lang.Exception
        Prints the classifications to the buffer.
        Parameters:
        classifier - the classifier to use for printing the classifications
        testset - the test instances
        Throws:
        java.lang.Exception - if check fails or error occurs during printing of classifications
      • printFooter

        public void printFooter()
                         throws java.lang.Exception
        Prints the footer to the buffer. This will also store the generated output in a file if an output file was specified.
        Throws:
        java.lang.Exception - if check fails
      • print

        public void print​(Classifier classifier,
                          ConverterUtils.DataSource testset)
                   throws java.lang.Exception
        Prints the header, classifications and footer to the buffer.
        Parameters:
        classifier - the classifier to use for printing the classifications
        testset - the data source to obtain the test instances from
        Throws:
        java.lang.Exception - if check fails or error occurs during printing of classifications
      • print

        public void print​(Classifier classifier,
                          Instances testset)
                   throws java.lang.Exception
        Prints the header, classifications and footer to the buffer.
        Parameters:
        classifier - the classifier to use for printing the classifications
        testset - the test instances
        Throws:
        java.lang.Exception - if check fails or error occurs during printing of classifications
      • fromCommandline

        public static AbstractOutput fromCommandline​(java.lang.String cmdline)
        Returns a fully configured object from the given commandline.
        Parameters:
        cmdline - the commandline to turn into an object
        Returns:
        the object or null in case of an error