Class AbstractOutput
java.lang.Object
weka.classifiers.evaluation.output.prediction.AbstractOutput
- All Implemented Interfaces:
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 Summary
-
Method Summary
Modifier and TypeMethodDescriptionReturns the tip text for this property.static AbstractOutput
fromCommandline
(String cmdline) Returns a fully configured object from the given commandline.boolean
Returns whether regular output is generated or not.Returns the range of attributes to output.Returns the current buffer.int
Returns the default number of digits to output after the decimal point.abstract String
Returns a short display text, to be used in comboboxes.Returns the header of the dataset.int
Returns the number of digits to output after the decimal point.String[]
Gets the current option settings for the OptionHandler.boolean
Returns whether to output the class distribution as well.Returns the output file to write to.boolean
Returns whether to the regular output is suppressed in case the output is stored in a file.abstract String
Returns a string describing the output generator.Returns an enumeration of all the available options..Returns the tip text for this property.Returns the tip text for this property.Returns the tip text for this property.void
print
(Classifier classifier, ConverterUtils.DataSource testset) Prints the header, classifications and footer to the buffer.void
print
(Classifier classifier, Instances testset) Prints the header, classifications and footer to the buffer.void
printClassification
(double[] dist, Instance inst, int index) Prints the classification to the buffer.void
printClassification
(Classifier classifier, Instance inst, int index) Prints the classification to the buffer.void
printClassifications
(Classifier classifier, ConverterUtils.DataSource testset) Prints the classifications to the buffer.void
printClassifications
(Classifier classifier, Instances testset) Prints the classifications to the buffer.void
Prints the footer to the buffer.void
Prints the header to the buffer.void
setAttributes
(String value) Sets the range of attributes to output.void
setBuffer
(StringBuffer value) Sets the buffer to use.void
Sets the header of the dataset.void
setNumDecimals
(int value) Sets the number of digits to output after the decimal point.void
setOptions
(String[] options) Sets the OptionHandler's options using the given list.void
setOutputDistribution
(boolean value) Sets whether to output the class distribution or not.void
setOutputFile
(File value) Sets the output file to write to.void
setSuppressOutput
(boolean value) Sets whether to the regular output is suppressed in case the output is stored in a file.Returns the tip text for this property.
-
Constructor Details
-
AbstractOutput
public AbstractOutput()Initializes the output class.
-
-
Method Details
-
globalInfo
Returns a string describing the output generator.- Returns:
- a description suitable for displaying in the GUI
-
getDisplay
Returns a short display text, to be used in comboboxes.- Returns:
- a short display text
-
listOptions
Returns an enumeration of all the available options..- Specified by:
listOptions
in interfaceOptionHandler
- Returns:
- an enumeration of all available options.
-
setOptions
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 interfaceOptionHandler
- Parameters:
options
- the list of options as an array of strings- Throws:
Exception
- if an option is not supported
-
getOptions
Gets the current option settings for the OptionHandler.- Specified by:
getOptions
in interfaceOptionHandler
- Returns:
- the list of current option settings as an array of strings
-
setHeader
Sets the header of the dataset.- Parameters:
value
- the header
-
getHeader
Returns the header of the dataset.- Returns:
- the header
-
setBuffer
Sets the buffer to use.- Parameters:
value
- the buffer
-
getBuffer
Returns the current buffer.- Returns:
- the buffer, can be null
-
setAttributes
Sets the range of attributes to output.- Parameters:
value
- the range
-
getAttributes
Returns the range of attributes to output.- Returns:
- the range
-
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
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
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI
-
setOutputFile
Sets the output file to write to. A directory disables this feature.- Parameters:
value
- the file to write to or a directory
-
getOutputFile
Returns the output file to write to. A directory if turned off.- Returns:
- the file to write to or a directory
-
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
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
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:
Exception
- if check fails or error occurs during printing of classification
-
printClassification
Prints 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:
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 classificationstestset
- the data source to obtain the test instances from- Throws:
Exception
- if check fails or error occurs during printing of classifications
-
printClassifications
Prints the classifications to the buffer.- Parameters:
classifier
- the classifier to use for printing the classificationstestset
- the test instances- Throws:
Exception
- if check fails or error occurs during printing of classifications
-
print
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:
Exception
- if check fails or error occurs during printing of classifications
-
print
Prints the header, classifications and footer to the buffer.- Parameters:
classifier
- the classifier to use for printing the classificationstestset
- the test instances- Throws:
Exception
- if check fails or error occurs during printing of classifications
-
fromCommandline
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
-