/*
 *   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 .
 */

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

package weka.filters.supervised.attribute;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.ObjectInputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.Vector;

import weka.classifiers.AbstractClassifier;
import weka.classifiers.Classifier;
import weka.classifiers.misc.InputMappedClassifier;
import weka.core.*;
import weka.filters.SimpleBatchFilter;

/**
 *  A filter for adding the classification, the class
 * distribution and an error flag to a dataset with a classifier. The classifier
 * is either trained on the data itself or provided as serialized model.
 * 

* * * Valid options are: *

* *

 * -D
 *  Turns on output of debugging information.
 * 
* *
 * -W <classifier specification>
 *  Full class name of classifier to use, followed
 *  by scheme options. eg:
 *   "weka.classifiers.bayes.NaiveBayes -D"
 *  (default: weka.classifiers.rules.ZeroR)
 * 
* *
 * -serialized <file>
 *  Instead of training a classifier on the data, one can also provide
 *  a serialized model and use that for tagging the data.
 * 
* *
 * -classification
 *  Adds an attribute with the actual classification.
 *  (default: off)
 * 
* *
 * -remove-old-class
 *  Removes the old class attribute.
 *  (default: off)
 * 
* *
 * -distribution
 *  Adds attributes with the distribution for all classes 
 *  (for numeric classes this will be identical to the attribute 
 *  output with '-classification').
 *  (default: off)
 * 
* *
 * -error
 *  Adds an attribute indicating whether the classifier output 
 *  a wrong classification (for numeric classes this is the numeric 
 *  difference).
 *  (default: off)
 * 
* * * * @author fracpete (fracpete at waikato dot ac dot nz) * @version $Revision: 14508 $ */ public class AddClassification extends SimpleBatchFilter implements WeightedAttributesHandler, WeightedInstancesHandler { /** for serialization. */ private static final long serialVersionUID = -1931467132568441909L; /** The classifier template used to do the classification. */ protected Classifier m_Classifier = new weka.classifiers.rules.ZeroR(); /** The file from which to load a serialized classifier. */ protected File m_SerializedClassifierFile = new File( System.getProperty("user.dir")); /** The actual classifier used to do the classification. */ protected Classifier m_ActualClassifier = null; /** the header of the file the serialized classifier was trained with. */ protected Instances m_SerializedHeader = null; /** whether to output the classification. */ protected boolean m_OutputClassification = false; /** whether to remove the old class attribute. */ protected boolean m_RemoveOldClass = false; /** whether to output the class distribution. */ protected boolean m_OutputDistribution = false; /** whether to output the error flag. */ protected boolean m_OutputErrorFlag = false; /** * Returns a string describing this filter. * * @return a description of the filter suitable for displaying in the * explorer/experimenter gui */ @Override public String globalInfo() { return "A filter for adding the classification, the class distribution and " + "an error flag to a dataset with a classifier. The classifier is " + "either trained on the data itself or provided as serialized model."; } /** * Returns an enumeration describing the available options. * * @return an enumeration of all the available options. */ @Override public Enumeration

Ads help maintain this website.