weka.classifiers.rules.PART Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of weka-dev Show documentation
Show all versions of weka-dev Show documentation
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.
/*
* 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 .
*/
/*
* PART.java
* Copyright (C) 1999-2012 University of Waikato, Hamilton, New Zealand
*
*/
package weka.classifiers.rules;
import java.util.Collections;
import java.util.Enumeration;
import java.util.Vector;
import weka.classifiers.AbstractClassifier;
import weka.classifiers.rules.part.MakeDecList;
import weka.classifiers.trees.j48.BinC45ModelSelection;
import weka.classifiers.trees.j48.C45ModelSelection;
import weka.classifiers.trees.j48.ModelSelection;
import weka.core.AdditionalMeasureProducer;
import weka.core.Capabilities;
import weka.core.Instance;
import weka.core.Instances;
import weka.core.Option;
import weka.core.OptionHandler;
import weka.core.RevisionUtils;
import weka.core.Summarizable;
import weka.core.TechnicalInformation;
import weka.core.TechnicalInformation.Field;
import weka.core.TechnicalInformation.Type;
import weka.core.TechnicalInformationHandler;
import weka.core.Utils;
import weka.core.WeightedInstancesHandler;
import weka.core.Capabilities;
import weka.core.Capabilities.Capability;
/**
* Class for generating a PART decision list. Uses
* separate-and-conquer. Builds a partial C4.5 decision tree in each iteration
* and makes the "best" leaf into a rule.
*
* For more information, see:
*
* Eibe Frank, Ian H. Witten: Generating Accurate Rule Sets Without Global
* Optimization. In: Fifteenth International Conference on Machine Learning,
* 144-151, 1998.
*
*
*
* BibTeX:
*
*
* @inproceedings{Frank1998,
* author = {Eibe Frank and Ian H. Witten},
* booktitle = {Fifteenth International Conference on Machine Learning},
* editor = {J. Shavlik},
* pages = {144-151},
* publisher = {Morgan Kaufmann},
* title = {Generating Accurate Rule Sets Without Global Optimization},
* year = {1998},
* PS = {http://www.cs.waikato.ac.nz/\~eibe/pubs/ML98-57.ps.gz}
* }
*
*
*
*
* Valid options are:
*
*
*
* -C <pruning confidence>
* Set confidence threshold for pruning.
* (default 0.25)
*
*
*
* -M <minimum number of objects>
* Set minimum number of objects per leaf.
* (default 2)
*
*
*
* -R
* Use reduced error pruning.
*
*
*
* -N <number of folds>
* Set number of folds for reduced error
* pruning. One fold is used as pruning set.
* (default 3)
*
*
*
* -B
* Use binary splits only.
*
*
*
* -U
* Generate unpruned decision list.
*
*
*
* -J
* Do not use MDL correction for info gain on numeric attributes.
*
*
*
* -Q <seed>
* Seed for random data shuffling (default 1).
*
*
*
* -doNotMakeSplitPointActualValue
* Do not make split point actual value.
*
*
*
*
* @author Eibe Frank ([email protected])
* @version $Revision: 11004 $
*/
public class PART extends AbstractClassifier implements OptionHandler,
WeightedInstancesHandler, Summarizable, AdditionalMeasureProducer,
TechnicalInformationHandler {
/** for serialization */
static final long serialVersionUID = 8121455039782598361L;
/** The decision list */
private MakeDecList m_root;
/** Confidence level */
private float m_CF = 0.25f;
/** Minimum number of objects */
private int m_minNumObj = 2;
/** Use MDL correction? */
private boolean m_useMDLcorrection = true;
/** Use reduced error pruning? */
private boolean m_reducedErrorPruning = false;
/** Number of folds for reduced error pruning. */
private int m_numFolds = 3;
/** Binary splits on nominal attributes? */
private boolean m_binarySplits = false;
/** Generate unpruned list? */
private boolean m_unpruned = false;
/** The seed for random number generation. */
private int m_Seed = 1;
/** Do not relocate split point to actual data value */
private boolean m_doNotMakeSplitPointActualValue;
/**
* Returns a string describing classifier
*
* @return a description suitable for displaying in the explorer/experimenter
* gui
*/
public String globalInfo() {
return "Class for generating a PART decision list. Uses "
+ "separate-and-conquer. Builds a partial C4.5 decision tree "
+ "in each iteration and makes the \"best\" leaf into a rule.\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;
result = new TechnicalInformation(Type.INPROCEEDINGS);
result.setValue(Field.AUTHOR, "Eibe Frank and Ian H. Witten");
result.setValue(Field.TITLE,
"Generating Accurate Rule Sets Without Global Optimization");
result.setValue(Field.BOOKTITLE,
"Fifteenth International Conference on Machine Learning");
result.setValue(Field.EDITOR, "J. Shavlik");
result.setValue(Field.YEAR, "1998");
result.setValue(Field.PAGES, "144-151");
result.setValue(Field.PUBLISHER, "Morgan Kaufmann");
result.setValue(Field.PS,
"http://www.cs.waikato.ac.nz/~eibe/pubs/ML98-57.ps.gz");
return result;
}
/**
* Returns default capabilities of the classifier.
*
* @return the capabilities of this classifier
*/
@Override
public Capabilities getCapabilities() {
Capabilities result;
result = new Capabilities(this);
result.disableAll();
// attributes
result.enable(Capability.NOMINAL_ATTRIBUTES);
result.enable(Capability.NUMERIC_ATTRIBUTES);
result.enable(Capability.DATE_ATTRIBUTES);
result.enable(Capability.MISSING_VALUES);
// class
result.enable(Capability.NOMINAL_CLASS);
result.enable(Capability.MISSING_CLASS_VALUES);
// instances
result.setMinimumNumberInstances(0);
return result;
}
/**
* Generates the classifier.
*
* @param instances the data to train with
* @throws Exception if classifier can't be built successfully
*/
@Override
public void buildClassifier(Instances instances) throws Exception {
// can classifier handle the data?
getCapabilities().testWithFail(instances);
// remove instances with missing class
instances = new Instances(instances);
instances.deleteWithMissingClass();
ModelSelection modSelection;
if (m_binarySplits) {
modSelection = new BinC45ModelSelection(m_minNumObj, instances,
m_useMDLcorrection, m_doNotMakeSplitPointActualValue);
} else {
modSelection = new C45ModelSelection(m_minNumObj, instances,
m_useMDLcorrection, m_doNotMakeSplitPointActualValue);
}
if (m_unpruned) {
m_root = new MakeDecList(modSelection, m_minNumObj);
} else if (m_reducedErrorPruning) {
m_root = new MakeDecList(modSelection, m_numFolds, m_minNumObj, m_Seed);
} else {
m_root = new MakeDecList(modSelection, m_CF, m_minNumObj);
}
m_root.buildClassifier(instances);
if (m_binarySplits) {
((BinC45ModelSelection) modSelection).cleanup();
} else {
((C45ModelSelection) modSelection).cleanup();
}
}
/**
* Classifies an instance.
*
* @param instance the instance to classify
* @return the classification
* @throws Exception if instance can't be classified successfully
*/
@Override
public double classifyInstance(Instance instance) throws Exception {
return m_root.classifyInstance(instance);
}
/**
* Returns class probabilities for an instance.
*
* @param instance the instance to get the distribution for
* @return the class probabilities
* @throws Exception if the distribution can't be computed successfully
*/
@Override
public final double[] distributionForInstance(Instance instance)
throws Exception {
return m_root.distributionForInstance(instance);
}
/**
* Returns an enumeration describing the available options.
*
* Valid options are:
*
*
* -C confidence
* Set confidence threshold for pruning. (Default: 0.25)
*
*
* -M number
* Set minimum number of instances per leaf. (Default: 2)
*
*
* -R
* Use reduced error pruning.
*
*
* -N number
* Set number of folds for reduced error pruning. One fold is used as the
* pruning set. (Default: 3)
*
*
* -B
* Use binary splits for nominal attributes.
*
*
* -U
* Generate unpruned decision list.
*
*
* -Q
* The seed for reduced-error pruning.
*
*
* @return an enumeration of all the available options.
*/
@Override
public Enumeration
© 2015 - 2024 Weber Informatics LLC | Privacy Policy