All Downloads are FREE. Search and download functionalities are using the official Maven repository.

weka.classifiers.evaluation.output.prediction.AbstractOutput Maven / Gradle / Ivy

Go to download

The Waikato Environment for Knowledge Analysis (WEKA), a machine learning workbench. This version represents the developer version, the "bleeding edge" of development, you could say. New functionality gets added to this version.

There is a newer version: 3.9.6
Show newest version
/*
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see .
 */

/*
 * AbstractOutput.java
 * Copyright (C) 2009-2012 University of Waikato, Hamilton, New Zealand
 */

package weka.classifiers.evaluation.output.prediction;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.Serializable;
import java.util.Enumeration;
import java.util.Vector;

import weka.classifiers.Classifier;
import weka.classifiers.misc.InputMappedClassifier;
import weka.core.*;
import weka.core.converters.ConverterUtils.DataSource;

/**
 * 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();
 * 
* * @author fracpete (fracpete at waikato dot ac dot nz) * @version $Revision: 14068 $ */ public abstract class AbstractOutput implements Serializable, OptionHandler { /** for serialization. */ private static final long serialVersionUID = 752696986017306241L; /** the header of the dataset. */ protected Instances m_Header; /** the buffer to write to. */ protected StringBuffer m_Buffer; /** the file buffer to write to. */ protected StringBuffer m_FileBuffer; /** whether to output the class distribution. */ protected boolean m_OutputDistribution; /** the range of attributes to output. */ protected Range m_Attributes; /** the number of decimals after the decimal point. */ protected int m_NumDecimals; /** the file to store the output in. */ protected File m_OutputFile; /** whether to suppress the regular output and only store in file. */ protected boolean m_SuppressOutput; /** * Initializes the output class. */ public AbstractOutput() { m_Header = null; m_OutputDistribution = false; m_Attributes = null; m_Buffer = null; m_NumDecimals = 3; m_OutputFile = new File("."); m_FileBuffer = new StringBuffer(); m_SuppressOutput = false; } /** * Returns a string describing the output generator. * * @return a description suitable for displaying in the GUI */ public abstract String globalInfo(); /** * Returns a short display text, to be used in comboboxes. * * @return a short display text */ public abstract String getDisplay(); /** * Returns an enumeration of all the available options.. * * @return an enumeration of all available options. */ @Override public Enumeration




© 2015 - 2024 Weber Informatics LLC | Privacy Policy