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

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

package weka.filters.unsupervised.attribute;

import java.util.Enumeration;
import java.util.Vector;

import weka.core.*;
import weka.core.TechnicalInformation.Field;
import weka.core.TechnicalInformation.Type;

/**
 *  Discretizes numeric attributes using equal
 * frequency binning and forces the number of bins to be equal to the square root of
 * the number of values of the numeric attribute.
*
* For more information, see:
*
* Ying Yang, Geoffrey I. Webb: Proportional k-Interval Discretization for * Naive-Bayes Classifiers. In: 12th European Conference on Machine Learning, * 564-575, 2001. *

* * * BibTeX: * *

 * @inproceedings{Yang2001,
 *    author = {Ying Yang and Geoffrey I. Webb},
 *    booktitle = {12th European Conference on Machine Learning},
 *    pages = {564-575},
 *    publisher = {Springer},
 *    series = {LNCS},
 *    title = {Proportional k-Interval Discretization for Naive-Bayes Classifiers},
 *    volume = {2167},
 *    year = {2001}
 * }
 * 
*

* * * Valid options are: *

* *

 * -unset-class-temporarily
 *  Unsets the class index temporarily before the filter is
 *  applied to the data.
 *  (default: no)
 * 
* *
 * -R <col1,col2-col4,...>
 *  Specifies list of columns to discretize. First and last are valid indexes.
 *  (default: first-last)
 * 
* *
 * -V
 *  Invert matching sense of column indexes.
 * 
* *
 * -D
 *  Output binary attributes for discretized attributes.
 * 
* * * * @author Richard Kirkby (rkirkby@cs.waikato.ac.nz) * @version $Revision: 14508 $ */ public class PKIDiscretize extends Discretize implements TechnicalInformationHandler, WeightedAttributesHandler, WeightedInstancesHandler { /** for serialization */ static final long serialVersionUID = 6153101248977702675L; /** * 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 { // alter child behaviour to do what we want m_FindNumBins = true; return super.setInputFormat(instanceInfo); } /** * Finds the number of bins to use and creates the cut points. * * @param index the attribute index */ @Override protected void findNumBins(int index) { Instances toFilter = getInputFormat(); // Find number of instances for attribute where not missing double sum = 0; for (Instance inst : toFilter) { if (!inst.isMissing(index)) { sum += inst.weight(); } } m_NumBins = (int) Math.sqrt(sum); if (m_NumBins > 0) { calculateCutPointsByEqualFrequencyBinning(index); } } /** * Gets an enumeration describing the available options. * * @return an enumeration of all the available options. */ @Override public Enumeration

Ads help maintain this website.