Class AbstractOutput

java.lang.Object
weka.classifiers.evaluation.output.prediction.AbstractOutput
All Implemented Interfaces:
Serializable, OptionHandler
Direct Known Subclasses:
CSV, HTML, InMemory, Null, PlainText, XML

public abstract class AbstractOutput extends Object implements 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: 14068 $
Author:
fracpete (fracpete at waikato dot ac dot nz)
See Also:
  • Constructor Details

    • AbstractOutput

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

    • globalInfo

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

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

      public 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(String[] options) throws 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:
      Exception - if an option is not supported
    • getOptions

      public 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(StringBuffer value)
      Sets the buffer to use.
      Parameters:
      value - the buffer
    • getBuffer

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

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

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

      public 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 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 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(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 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 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 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 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:
      Exception - if check fails or error occurs during printing of classification
    • printClassification

      public void printClassification(double[] dist, Instance inst, int index) throws 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:
      Exception - if check fails or error occurs during printing of classification
    • printClassifications

      public void printClassifications(Classifier classifier, ConverterUtils.DataSource testset) throws 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:
      Exception - if check fails or error occurs during printing of classifications
    • printClassifications

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

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

      public void print(Classifier classifier, ConverterUtils.DataSource testset) throws 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:
      Exception - if check fails or error occurs during printing of classifications
    • print

      public void print(Classifier classifier, Instances testset) throws 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:
      Exception - if check fails or error occurs during printing of classifications
    • fromCommandline

      public static AbstractOutput fromCommandline(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