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

weka.attributeSelection.ReliefFAttributeEval 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 .
 */

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

package weka.attributeSelection;

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

import weka.core.Attribute;
import weka.core.Capabilities;
import weka.core.Capabilities.Capability;
import weka.core.Instance;
import weka.core.Instances;
import weka.core.Option;
import weka.core.OptionHandler;
import weka.core.RevisionUtils;
import weka.core.TechnicalInformation;
import weka.core.TechnicalInformation.Field;
import weka.core.TechnicalInformation.Type;
import weka.core.TechnicalInformationHandler;
import weka.core.Utils;

/**
 *  ReliefFAttributeEval :
*
* Evaluates the worth of an attribute by repeatedly sampling an instance and * considering the value of the given attribute for the nearest instance of the * same and different class. Can operate on both discrete and continuous class * data.
*
* For more information see:
*
* Kenji Kira, Larry A. Rendell: A Practical Approach to Feature Selection. In: * Ninth International Workshop on Machine Learning, 249-256, 1992.
*
* Igor Kononenko: Estimating Attributes: Analysis and Extensions of RELIEF. In: * European Conference on Machine Learning, 171-182, 1994.
*
* Marko Robnik-Sikonja, Igor Kononenko: An adaptation of Relief for attribute * estimation in regression. In: Fourteenth International Conference on Machine * Learning, 296-304, 1997. *

* * * BibTeX: * *

 * @inproceedings{Kira1992,
 *    author = {Kenji Kira and Larry A. Rendell},
 *    booktitle = {Ninth International Workshop on Machine Learning},
 *    editor = {Derek H. Sleeman and Peter Edwards},
 *    pages = {249-256},
 *    publisher = {Morgan Kaufmann},
 *    title = {A Practical Approach to Feature Selection},
 *    year = {1992}
 * }
 * 
 * @inproceedings{Kononenko1994,
 *    author = {Igor Kononenko},
 *    booktitle = {European Conference on Machine Learning},
 *    editor = {Francesco Bergadano and Luc De Raedt},
 *    pages = {171-182},
 *    publisher = {Springer},
 *    title = {Estimating Attributes: Analysis and Extensions of RELIEF},
 *    year = {1994}
 * }
 * 
 * @inproceedings{Robnik-Sikonja1997,
 *    author = {Marko Robnik-Sikonja and Igor Kononenko},
 *    booktitle = {Fourteenth International Conference on Machine Learning},
 *    editor = {Douglas H. Fisher},
 *    pages = {296-304},
 *    publisher = {Morgan Kaufmann},
 *    title = {An adaptation of Relief for attribute estimation in regression},
 *    year = {1997}
 * }
 * 
*

* * * Valid options are: *

* *

 * -M <num instances>
 *  Specify the number of instances to
 *  sample when estimating attributes.
 *  If not specified, then all instances
 *  will be used.
 * 
* *
 * -D <seed>
 *  Seed for randomly sampling instances.
 *  (Default = 1)
 * 
* *
 * -K <number of neighbours>
 *  Number of nearest neighbours (k) used
 *  to estimate attribute relevances
 *  (Default = 10).
 * 
* *
 * -W
 *  Weight nearest neighbours by distance
 * 
* *
 * -A <num>
 *  Specify sigma value (used in an exp
 *  function to control how quickly
 *  weights for more distant instances
 *  decrease. Use in conjunction with -W.
 *  Sensible value=1/5 to 1/10 of the
 *  number of nearest neighbours.
 *  (Default = 2)
 * 
* * * * @author Mark Hall ([email protected]) * @version $Revision: 13374 $ */ public class ReliefFAttributeEval extends ASEvaluation implements AttributeEvaluator, OptionHandler, TechnicalInformationHandler { /** for serialization */ static final long serialVersionUID = -8422186665795839379L; /** The training instances */ private Instances m_trainInstances; /** The class index */ private int m_classIndex; /** The number of attributes */ private int m_numAttribs; /** The number of instances */ private int m_numInstances; /** Numeric class */ private boolean m_numericClass; /** The number of classes if class is nominal */ private int m_numClasses; /** * Used to hold the probability of a different class val given nearest * instances (numeric class) */ private double m_ndc; /** * Used to hold the prob of different value of an attribute given nearest * instances (numeric class case) */ private double[] m_nda; /** * Used to hold the prob of a different class val and different att val given * nearest instances (numeric class case) */ private double[] m_ndcda; /** Holds the weights that relief assigns to attributes */ private double[] m_weights; /** Prior class probabilities (discrete class case) */ private double[] m_classProbs; /** * The number of instances to sample when estimating attributes default == -1, * use all instances */ private int m_sampleM; /** The number of nearest hits/misses */ private int m_Knn; /** k nearest scores + instance indexes for n classes */ private double[][][] m_karray; /** Upper bound for numeric attributes */ private double[] m_maxArray; /** Lower bound for numeric attributes */ private double[] m_minArray; /** Keep track of the farthest instance for each class */ private double[] m_worst; /** Index in the m_karray of the farthest instance for each class */ private int[] m_index; /** Number of nearest neighbours stored of each class */ private int[] m_stored; /** Random number seed used for sampling instances */ private int m_seed; /** * used to (optionally) weight nearest neighbours by their distance from the * instance in question. Each entry holds exp(-((rank(r_i, i_j)/sigma)^2)) * where rank(r_i,i_j) is the rank of instance i_j in a sequence of instances * ordered by the distance from r_i. sigma is a user defined parameter, * default=20 **/ private double[] m_weightsByRank; private int m_sigma; /** Weight by distance rather than equal weights */ private boolean m_weightByDistance; /** * Constructor */ public ReliefFAttributeEval() { resetOptions(); } /** * Returns a string describing this attribute evaluator * * @return a description of the evaluator suitable for displaying in the * explorer/experimenter gui */ public String globalInfo() { return "ReliefFAttributeEval :\n\nEvaluates the worth of an attribute by " + "repeatedly sampling an instance and considering the value of the " + "given attribute for the nearest instance of the same and different " + "class. Can operate on both discrete and continuous class data.\n\n" + "For more information see:\n\n" + getTechnicalInformation().toString(); } /** * Returns an instance of a TechnicalInformation object, containing detailed * information about the technical background of this class, e.g., paper * reference or book this class is based on. * * @return the technical information about this class */ @Override public TechnicalInformation getTechnicalInformation() { TechnicalInformation result; TechnicalInformation additional; result = new TechnicalInformation(Type.INPROCEEDINGS); result.setValue(Field.AUTHOR, "Kenji Kira and Larry A. Rendell"); result.setValue(Field.TITLE, "A Practical Approach to Feature Selection"); result.setValue(Field.BOOKTITLE, "Ninth International Workshop on Machine Learning"); result.setValue(Field.EDITOR, "Derek H. Sleeman and Peter Edwards"); result.setValue(Field.YEAR, "1992"); result.setValue(Field.PAGES, "249-256"); result.setValue(Field.PUBLISHER, "Morgan Kaufmann"); additional = result.add(Type.INPROCEEDINGS); additional.setValue(Field.AUTHOR, "Igor Kononenko"); additional.setValue(Field.TITLE, "Estimating Attributes: Analysis and Extensions of RELIEF"); additional.setValue(Field.BOOKTITLE, "European Conference on Machine Learning"); additional.setValue(Field.EDITOR, "Francesco Bergadano and Luc De Raedt"); additional.setValue(Field.YEAR, "1994"); additional.setValue(Field.PAGES, "171-182"); additional.setValue(Field.PUBLISHER, "Springer"); additional = result.add(Type.INPROCEEDINGS); additional .setValue(Field.AUTHOR, "Marko Robnik-Sikonja and Igor Kononenko"); additional.setValue(Field.TITLE, "An adaptation of Relief for attribute estimation in regression"); additional.setValue(Field.BOOKTITLE, "Fourteenth International Conference on Machine Learning"); additional.setValue(Field.EDITOR, "Douglas H. Fisher"); additional.setValue(Field.YEAR, "1997"); additional.setValue(Field.PAGES, "296-304"); additional.setValue(Field.PUBLISHER, "Morgan Kaufmann"); return result; } /** * Returns an enumeration describing the available options. * * @return an enumeration of all the available options. **/ @Override public Enumeration




© 2015 - 2024 Weber Informatics LLC | Privacy Policy