Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
The Waikato Environment for Knowledge Analysis (WEKA), a machine
learning workbench. This is the stable version. Apart from bugfixes, this version
does not receive any other updates.
/*
* 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 .
*/
/*
* NominalToBinary.java
* Copyright (C) 1999-2012 University of Waikato, Hamilton, New Zealand
*
*/
package weka.filters.unsupervised.attribute;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Vector;
import weka.core.Attribute;
import weka.core.Capabilities;
import weka.core.Capabilities.Capability;
import weka.core.DenseInstance;
import weka.core.Instance;
import weka.core.Instances;
import weka.core.Option;
import weka.core.OptionHandler;
import weka.core.Range;
import weka.core.RevisionUtils;
import weka.core.SparseInstance;
import weka.core.Utils;
import weka.filters.Filter;
import weka.filters.StreamableFilter;
import weka.filters.UnsupervisedFilter;
/**
* Converts all nominal attributes into binary numeric
* attributes. An attribute with k values is transformed into k binary
* attributes if the class is nominal (using the one-attribute-per-value
* approach). Binary attributes are left binary, if option '-A' is not given.If
* the class is numeric, you might want to use the supervised version of this
* filter.
*
*
*
* Valid options are:
*
*
*
* -N
* Sets if binary attributes are to be coded as nominal ones.
*
*
*
* -A
* For each nominal value a new attribute is created,
* not only if there are more than 2 values.
*
*
*
* -R <col1,col2-col4,...>
* Specifies list of columns to act on. First and last are
* valid indexes.
* (default: first-last)
*
*
*
* -V
* Invert matching sense of column indexes.
*
*
*
*
* @author Eibe Frank ([email protected])
* @version $Revision: 12037 $
*/
public class NominalToBinary extends Filter implements UnsupervisedFilter,
OptionHandler, StreamableFilter {
/** for serialization */
static final long serialVersionUID = -1130642825710549138L;
/** Stores which columns to act on */
protected Range m_Columns = new Range();
/** Are the new attributes going to be nominal or numeric ones? */
private boolean m_Numeric = true;
/** Are all values transformed into new attributes? */
private boolean m_TransformAll = false;
/** Whether we need to transform at all */
private boolean m_needToTransform = false;
/** Constructor - initialises the filter */
public NominalToBinary() {
setAttributeIndices("first-last");
}
/**
* Returns a string describing this filter
*
* @return a description of the filter suitable for displaying in the
* explorer/experimenter gui
*/
public String globalInfo() {
return "Converts all nominal attributes into binary numeric attributes. An "
+ "attribute with k values is transformed into k binary attributes if "
+ "the class is nominal (using the one-attribute-per-value approach). "
+ "Binary attributes are left binary, if option '-A' is not given."
+ "If the class is numeric, you might want to use the supervised version of "
+ "this filter.";
}
/**
* Returns the Capabilities of this filter.
*
* @return the capabilities of this object
* @see Capabilities
*/
@Override
public Capabilities getCapabilities() {
Capabilities result = super.getCapabilities();
result.disableAll();
// attributes
result.enableAllAttributes();
result.enable(Capability.MISSING_VALUES);
// class
result.enableAllClasses();
result.enable(Capability.MISSING_CLASS_VALUES);
result.enable(Capability.NO_CLASS);
return result;
}
/**
* Sets the format of the input instances.
*
* @param instanceInfo an Instances object containing the input instance
* structure (any instances contained in the object are ignored -
* only the structure is required).
* @return true if the outputFormat may be collected immediately
* @throws Exception if the input format can't be set successfully
*/
@Override
public boolean setInputFormat(Instances instanceInfo) throws Exception {
super.setInputFormat(instanceInfo);
m_Columns.setUpper(instanceInfo.numAttributes() - 1);
setOutputFormat();
return true;
}
/**
* Input an instance for filtering. Filter requires all training instances be
* read before producing output.
*
* @param instance the input instance
* @return true if the filtered instance may now be collected with output().
* @throws IllegalStateException if no input format has been set
*/
@Override
public boolean input(Instance instance) {
if (getInputFormat() == null) {
throw new IllegalStateException("No input instance format defined");
}
if (m_NewBatch) {
resetQueue();
m_NewBatch = false;
}
convertInstance(instance);
return true;
}
/**
* Returns an enumeration describing the available options.
*
* @return an enumeration of all the available options.
*/
@Override
public Enumeration