Class AbstractOutput
- java.lang.Object
-
- weka.classifiers.evaluation.output.prediction.AbstractOutput
-
- All Implemented Interfaces:
java.io.Serializable,OptionHandler
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 Summary
Constructors Constructor Description AbstractOutput()Initializes the output class.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description java.lang.StringattributesTipText()Returns the tip text for this property.static AbstractOutputfromCommandline(java.lang.String cmdline)Returns a fully configured object from the given commandline.booleangeneratesOutput()Returns whether regular output is generated or not.java.lang.StringgetAttributes()Returns the range of attributes to output.java.lang.StringBuffergetBuffer()Returns the current buffer.intgetDefaultNumDecimals()Returns the default number of digits to output after the decimal point.abstract java.lang.StringgetDisplay()Returns a short display text, to be used in comboboxes.InstancesgetHeader()Returns the header of the dataset.intgetNumDecimals()Returns the number of digits to output after the decimal point.java.lang.String[]getOptions()Gets the current option settings for the OptionHandler.booleangetOutputDistribution()Returns whether to output the class distribution as well.java.io.FilegetOutputFile()Returns the output file to write to.booleangetSuppressOutput()Returns whether to the regular output is suppressed in case the output is stored in a file.abstract java.lang.StringglobalInfo()Returns a string describing the output generator.java.util.Enumeration<Option>listOptions()Returns an enumeration of all the available options..java.lang.StringnumDecimalsTipText()Returns the tip text for this property.java.lang.StringoutputDistributionTipText()Returns the tip text for this property.java.lang.StringoutputFileTipText()Returns the tip text for this property.voidprint(Classifier classifier, ConverterUtils.DataSource testset)Prints the header, classifications and footer to the buffer.voidprint(Classifier classifier, Instances testset)Prints the header, classifications and footer to the buffer.voidprintClassification(double[] dist, Instance inst, int index)Prints the classification to the buffer.voidprintClassification(Classifier classifier, Instance inst, int index)Prints the classification to the buffer.voidprintClassifications(Classifier classifier, ConverterUtils.DataSource testset)Prints the classifications to the buffer.voidprintClassifications(Classifier classifier, Instances testset)Prints the classifications to the buffer.voidprintFooter()Prints the footer to the buffer.voidprintHeader()Prints the header to the buffer.voidsetAttributes(java.lang.String value)Sets the range of attributes to output.voidsetBuffer(java.lang.StringBuffer value)Sets the buffer to use.voidsetHeader(Instances value)Sets the header of the dataset.voidsetNumDecimals(int value)Sets the number of digits to output after the decimal point.voidsetOptions(java.lang.String[] options)Sets the OptionHandler's options using the given list.voidsetOutputDistribution(boolean value)Sets whether to output the class distribution or not.voidsetOutputFile(java.io.File value)Sets the output file to write to.voidsetSuppressOutput(boolean value)Sets whether to the regular output is suppressed in case the output is stored in a file.java.lang.StringsuppressOutputTipText()Returns the tip text for this property.
-
-
-
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:
listOptionsin interfaceOptionHandler- Returns:
- an enumeration of all available options.
-
setOptions
public void setOptions(java.lang.String[] options) throws java.lang.ExceptionSets 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:
setOptionsin interfaceOptionHandler- 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:
getOptionsin interfaceOptionHandler- 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 classificationinst- the instance to printindex- 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.ExceptionPrints the classification to the buffer.- Parameters:
dist- the distribution from classifier for the supplied instanceinst- the instance to printindex- 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 classificationstestset- 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 classificationstestset- the test instances- Throws:
java.lang.Exception- if check fails or error occurs during printing of classifications
-
printFooter
public void printFooter() throws java.lang.ExceptionPrints 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 classificationstestset- 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 classificationstestset- 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
-
-