public abstract class AbstractOutput extends java.lang.Object implements java.io.Serializable, OptionHandler
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();
| Modifier and Type | Field and Description |
|---|---|
protected Range |
m_Attributes
the range of attributes to output.
|
protected java.lang.StringBuffer |
m_Buffer
the buffer to write to.
|
protected java.lang.StringBuffer |
m_FileBuffer
the file buffer to write to.
|
protected Instances |
m_Header
the header of the dataset.
|
protected int |
m_NumDecimals
the number of decimals after the decimal point.
|
protected boolean |
m_OutputDistribution
whether to output the class distribution.
|
protected java.io.File |
m_OutputFile
the file to store the output in.
|
protected boolean |
m_SuppressOutput
whether to suppress the regular output and only store in file.
|
| Constructor and Description |
|---|
AbstractOutput()
Initializes the output class.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
append(java.lang.String s)
If an output file was defined, then the string gets added to the file
buffer, otherwise to the actual buffer.
|
java.lang.String |
attributesTipText()
Returns the tip text for this property.
|
protected java.lang.String |
checkBasic()
Performs basic checks.
|
protected java.lang.String |
checkHeader()
Performs checks whether everything is correctly setup for the header.
|
protected abstract void |
doPrintClassification(Classifier classifier,
Instance inst,
int index)
Performs the actual printing of the classification.
|
protected abstract void |
doPrintClassification(double[] dist,
Instance inst,
int index)
Performs the actual printing of the classification.
|
protected abstract void |
doPrintFooter()
Performs the actual printing of the footer.
|
protected abstract void |
doPrintHeader()
Performs the actual printing of the header.
|
static AbstractOutput |
fromCommandline(java.lang.String cmdline)
Returns a fully configured object from the given commandline.
|
boolean |
generatesOutput()
Returns whether regular output is generated or not.
|
java.lang.String |
getAttributes()
Returns the range of attributes to output.
|
java.lang.StringBuffer |
getBuffer()
Returns the current buffer.
|
int |
getDefaultNumDecimals()
Returns the default number of digits to output after the decimal point.
|
abstract java.lang.String |
getDisplay()
Returns a short display text, to be used in comboboxes.
|
Instances |
getHeader()
Returns the header of the dataset.
|
int |
getNumDecimals()
Returns the number of digits to output after the decimal point.
|
java.lang.String[] |
getOptions()
Gets the current option settings for the OptionHandler.
|
boolean |
getOutputDistribution()
Returns whether to output the class distribution as well.
|
java.io.File |
getOutputFile()
Returns the output file to write to.
|
boolean |
getSuppressOutput()
Returns whether to the regular output is suppressed in case the output is
stored in a file.
|
abstract java.lang.String |
globalInfo()
Returns a string describing the output generator.
|
java.util.Enumeration<Option> |
listOptions()
Returns an enumeration of all the available options..
|
java.lang.String |
numDecimalsTipText()
Returns the tip text for this property.
|
java.lang.String |
outputDistributionTipText()
Returns the tip text for this property.
|
java.lang.String |
outputFileTipText()
Returns the tip text for this property.
|
protected Instance |
preProcessInstance(Instance inst,
Classifier classifier)
Preprocesses an input instance.
|
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(Classifier classifier,
Instance inst,
int index)
Prints the classification to the buffer.
|
void |
printClassification(double[] dist,
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 |
printFooter()
Prints the footer to the buffer.
|
void |
printHeader()
Prints the header to the buffer.
|
void |
setAttributes(java.lang.String value)
Sets the range of attributes to output.
|
void |
setBuffer(java.lang.StringBuffer value)
Sets the buffer to use.
|
void |
setHeader(Instances value)
Sets the header of the dataset.
|
void |
setNumDecimals(int value)
Sets the number of digits to output after the decimal point.
|
void |
setOptions(java.lang.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(java.io.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.
|
java.lang.String |
suppressOutputTipText()
Returns the tip text for this property.
|
protected Instances m_Header
protected java.lang.StringBuffer m_Buffer
protected java.lang.StringBuffer m_FileBuffer
protected boolean m_OutputDistribution
protected Range m_Attributes
protected int m_NumDecimals
protected java.io.File m_OutputFile
protected boolean m_SuppressOutput
public abstract java.lang.String globalInfo()
public abstract java.lang.String getDisplay()
public java.util.Enumeration<Option> listOptions()
listOptions in interface OptionHandlerpublic void setOptions(java.lang.String[] options)
throws java.lang.Exception
setOptions in interface OptionHandleroptions - the list of options as an array of stringsjava.lang.Exception - if an option is not supportedpublic java.lang.String[] getOptions()
getOptions in interface OptionHandlerpublic void setHeader(Instances value)
value - the headerpublic Instances getHeader()
public void setBuffer(java.lang.StringBuffer value)
value - the bufferpublic java.lang.StringBuffer getBuffer()
public void setAttributes(java.lang.String value)
value - the rangepublic java.lang.String getAttributes()
public java.lang.String attributesTipText()
public void setOutputDistribution(boolean value)
value - true if the class distribution is to be output as wellpublic boolean getOutputDistribution()
public java.lang.String outputDistributionTipText()
public int getDefaultNumDecimals()
public void setNumDecimals(int value)
value - the number of digitspublic int getNumDecimals()
public java.lang.String numDecimalsTipText()
public void setOutputFile(java.io.File value)
value - the file to write to or a directorypublic java.io.File getOutputFile()
public java.lang.String outputFileTipText()
public void setSuppressOutput(boolean value)
value - true if the regular output is to be suppressedpublic boolean getSuppressOutput()
public java.lang.String suppressOutputTipText()
protected java.lang.String checkBasic()
public boolean generatesOutput()
protected void append(java.lang.String s)
s - the string to appendm_Buffer,
m_FileBufferprotected java.lang.String checkHeader()
protected abstract void doPrintHeader()
public void printHeader()
protected abstract void doPrintClassification(Classifier classifier, Instance inst, int index) throws java.lang.Exception
classifier - the classifier to use for printing the classificationinst - the instance to printindex - the index of the instancejava.lang.Exception - if printing of classification failsprotected abstract void doPrintClassification(double[] dist,
Instance inst,
int index)
throws java.lang.Exception
dist - the distribution to use for printing the classificationinst - the instance to printindex - the index of the instancejava.lang.Exception - if printing of classification failsprotected Instance preProcessInstance(Instance inst, Classifier classifier) throws java.lang.Exception
inst - the original instance to predictclassifier - the classifier that will be used to make the predictionjava.lang.Exception - if a problem occurs.public void printClassification(Classifier classifier, Instance inst, int index) throws java.lang.Exception
classifier - the classifier to use for printing the classificationinst - the instance to printindex - the index of the instancejava.lang.Exception - if check fails or error occurs during printing of
classificationpublic void printClassification(double[] dist,
Instance inst,
int index)
throws java.lang.Exception
dist - the distribution from classifier for the supplied instanceinst - the instance to printindex - the index of the instancejava.lang.Exception - if check fails or error occurs during printing of
classificationpublic void printClassifications(Classifier classifier, ConverterUtils.DataSource testset) throws java.lang.Exception
classifier - the classifier to use for printing the classificationstestset - the data source to obtain the test instances fromjava.lang.Exception - if check fails or error occurs during printing of
classificationspublic void printClassifications(Classifier classifier, Instances testset) throws java.lang.Exception
classifier - the classifier to use for printing the classificationstestset - the test instancesjava.lang.Exception - if check fails or error occurs during printing of
classificationsprotected abstract void doPrintFooter()
public void printFooter()
throws java.lang.Exception
java.lang.Exception - if check failspublic void print(Classifier classifier, ConverterUtils.DataSource testset) throws java.lang.Exception
classifier - the classifier to use for printing the classificationstestset - the data source to obtain the test instances fromjava.lang.Exception - if check fails or error occurs during printing of
classificationspublic void print(Classifier classifier, Instances testset) throws java.lang.Exception
classifier - the classifier to use for printing the classificationstestset - the test instancesjava.lang.Exception - if check fails or error occurs during printing of
classificationspublic static AbstractOutput fromCommandline(java.lang.String cmdline)
cmdline - the commandline to turn into an object