coser.classifiers.trees
类 CostJ48

java.lang.Object
  继承者 Classifier
      继承者 coser.classifiers.trees.CostJ48

public class CostJ48
extends Classifier

Summary: Cost-sensitive decision tree, revised from J48.java. For more information please refer to our papers:
\@INPROCEEDINGS{MinZhu11MinimalCost,
author = {Fan Min and William Zhu},
title = {},
booktitle = {Proceedings of International Conference on Database Theory and Application},
series = {FGIT-DTA/BSBT, CCIS},
volume = {258},
year = {2011},
pages = {100--107}
}

Author: Fan Min minfanphd@163.com
Copyright: The source code and all documents are open and free. PLEASE keep this header while revising the program.

Organizaion: Lab of Granular Computing, Zhangzhou Normal University, Fujian 363000, China.
Project: The cost-sensitive rough sets project.

Progress: Copied from J48.java.
Written time: March 1, 2011.
Last modify time: March 20, 2012.


字段摘要
修饰符 和 类型 字段 和 描述
static boolean[] attributeTested
          Tha array saving tested attributes
 int[][] costMatrix
          The misclassification cost matrix
static boolean dataType
          The data type of the decision system.
static double lambda
          The exponention of the test cost.
static int POST_PRUNE
          Post-prune the initial tree.
static int PRE_PRUNE
          Pre-prune the initial tree.
 coser.classifiers.trees.csj48.ClassifierTree root
          The decision tree 决策树
(专用软件包) static long serialVersionUID
          for serialization
 int[] testcostArray
          The test cost array
static int UN_PRUNE
          Do not prune the initial tree.
 
构造方法摘要
构造函数 和 描述
CostJ48()
          The constructor 1
CostJ48(coser.classifiers.trees.csj48.ClassifierTree paraRoot, double paraLambda, boolean paraUnpruned, float paraConfidenceFactor, int paraMinNumObj, boolean paraUseLaplace, boolean paraReducedErrorPruning, int paraNumFolds, boolean paraBinarySplits, boolean paraSubtreeRaising, boolean paraNoCleanup, int paraPruneStrategy, int paraSeed)
          The constructor 2
 
方法摘要
修饰符 和 类型 方法 和 描述
 java.lang.String binarySplitsTipText()
          Returns the tip text for this property
 void buildClassifier(Instances instances)
          Generates the classifier.
 double classifyInstance(Instance instance)
          Classifies an instance.
 double computeCost(coser.classifiers.trees.csj48.ClassifierTree paraTree)
          Compute the cost of the decision tree.
 int computeTestcost(boolean[] paraTest)
          Compute the test cost
 java.lang.String confidenceFactorTipText()
          Returns the tip text for this property
 double[] distributionForInstance(Instance instance)
          Returns class probabilities for an instance.
 java.util.Enumeration<java.lang.String> enumerateMeasures()
          Returns an enumeration of the additional measure names
 void evaluate()
          Evaluate the generated decision tree.
 boolean getBinarySplits()
          Get the value of binarySplits.
 Capabilities getCapabilities()
          Returns default capabilities of the classifier.
 float getConfidenceFactor()
          Get the value of CF.
 double getMeasure(java.lang.String additionalMeasureName)
          Returns the value of the named measure
 int getMinNumObj()
          Get the value of minNumObj.
 int getNumFolds()
          Get the value of numFolds.
 java.lang.String[] getOptions()
          Gets the current settings of the Classifier.
 boolean getReducedErrorPruning()
          Get the value of reducedErrorPruning.
 java.lang.String getRevision()
          Returns the revision string.
 boolean getSaveInstanceData()
          Check whether instance data is to be saved.
 int getSeed()
          Get the value of Seed.
 boolean getSubtreeRaising()
          Get the value of subtreeRaising.
 TechnicalInformation getTechnicalInformation()
          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.
 boolean getUnpruned()
          Get the value of unpruned.
 boolean getUseLaplace()
          Get the value of useLaplace.
 java.lang.String globalInfo()
          Returns a string describing classifier
 java.lang.String graph()
          Returns graph describing the tree.
 int graphType()
          Returns the type of graph this classifier represents.
 java.util.Enumeration<Option> listOptions()
          Returns an enumeration describing the available options.
static void main(java.lang.String[] argv)
          Main method for testing this class
 double measureNumLeaves()
          Returns the number of leaves
 double measureNumRules()
          Returns the number of rules (same as number of leaves)
 double measureTreeSize()
          Returns the size of the tree
 java.lang.String minNumObjTipText()
          Returns the tip text for this property
 java.lang.String numFoldsTipText()
          Returns the tip text for this property
 void postPrune(coser.classifiers.trees.csj48.ClassifierTree paraRoot)
          Post prune the created decision tree.
 void postPrune(CostJ48 paraCostJ48)
          Post prune the decision tree according to the average cost.
 java.lang.String prefix()
          Returns tree in prefix order.
 void prePrune()
          Pre prune the created decision tree.
 void prune(int pruneStrategy)
          Prune the generated C4.5 decision tree.
 java.lang.String reducedErrorPruningTipText()
          Returns the tip text for this property
 java.lang.String saveInstanceDataTipText()
          Returns the tip text for this property
 java.lang.String seedTipText()
          Returns the tip text for this property
 void setBinarySplits(boolean v)
          Set the value of binarySplits.
 void setConfidenceFactor(float v)
          Set the value of CF.
 void setMinNumObj(int v)
          Set the value of minNumObj.
 void setMisclassificationCostMatrix(int[][] paraCostMatrix)
          Set the misclassification cost matrix
 void setNumFolds(int v)
          Set the value of numFolds.
 void setOptions(java.lang.String[] options)
          Parses a given list of options
 void setReducedErrorPruning(boolean v)
          Set the value of reducedErrorPruning.
 void setSaveInstanceData(boolean v)
          Set whether instance data is to be saved.
 void setSeed(int newSeed)
          Set the value of Seed.
 void setSubtreeRaising(boolean v)
          Set the value of subtreeRaising.
 void setTestcostArray(int[] paraTestcostArray)
          Set the test cost array
 void setUnpruned(boolean v)
          Set the value of unpruned.
 void setUseLaplace(boolean paraUseLaplace)
          Set the value of useLaplace.
 java.lang.String subtreeRaisingTipText()
          Returns the tip text for this property
 java.lang.String toSource(java.lang.String className)
          Returns tree as an if-then statement.
 java.lang.String toString()
          Returns a description of the classifier.
 java.lang.String toSummaryString()
          Returns a superconcise version of the model
 java.lang.String unprunedTipText()
          Returns the tip text for this property
 java.lang.String useLaplaceTipText()
          Returns the tip text for this property
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

字段详细信息

serialVersionUID

static final long serialVersionUID
for serialization

另请参见:
常量字段值

dataType

public static boolean dataType
The data type of the decision system.
false represents the nominal decision system.
true represents the numberic decision system.


UN_PRUNE

public static final int UN_PRUNE
Do not prune the initial tree.

另请参见:
常量字段值

PRE_PRUNE

public static final int PRE_PRUNE
Pre-prune the initial tree.

另请参见:
常量字段值

POST_PRUNE

public static final int POST_PRUNE
Post-prune the initial tree.

另请参见:
常量字段值

root

public coser.classifiers.trees.csj48.ClassifierTree root
The decision tree 决策树


lambda

public static double lambda
The exponention of the test cost.


attributeTested

public static boolean[] attributeTested
Tha array saving tested attributes


testcostArray

public int[] testcostArray
The test cost array


costMatrix

public int[][] costMatrix
The misclassification cost matrix

构造方法详细信息

CostJ48

public CostJ48()
The constructor 1


CostJ48

public CostJ48(coser.classifiers.trees.csj48.ClassifierTree paraRoot,
               double paraLambda,
               boolean paraUnpruned,
               float paraConfidenceFactor,
               int paraMinNumObj,
               boolean paraUseLaplace,
               boolean paraReducedErrorPruning,
               int paraNumFolds,
               boolean paraBinarySplits,
               boolean paraSubtreeRaising,
               boolean paraNoCleanup,
               int paraPruneStrategy,
               int paraSeed)
The constructor 2

方法详细信息

globalInfo

public java.lang.String globalInfo()
Returns a string describing classifier

返回:
a description suitable for displaying in the explorer/experimenter gui

getTechnicalInformation

public TechnicalInformation getTechnicalInformation()
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.

返回:
the technical information about this class

getCapabilities

public Capabilities getCapabilities()
Returns default capabilities of the classifier.

返回:
the capabilities of this classifier

buildClassifier

public void buildClassifier(Instances instances)
                     throws java.lang.Exception
Generates the classifier.

参数:
instances - the data to train the classifier with
抛出:
java.lang.Exception - if classifier can't be built successfully

prune

public void prune(int pruneStrategy)
Prune the generated C4.5 decision tree.
The pruning object is to minimize the total cost, including the test cost and the misclassification cost.


prePrune

public void prePrune()
Pre prune the created decision tree.


postPrune

public void postPrune(CostJ48 paraCostJ48)
Post prune the decision tree according to the average cost.
Post-order recursive


postPrune

public void postPrune(coser.classifiers.trees.csj48.ClassifierTree paraRoot)
Post prune the created decision tree.
后序遍历剪枝
递归法
所有非叶子结点都含有属性测试信息和划分信息。(对于名词型决策系统而言)
对于任意一个以某测试为根结点的代价敏感决策树。比较测试该属性的代价(测试代价+误分类代价)和不测试该属性的代价(误分类代价)。
如果是前者大,就剪枝即不测试当前结点所代表的属性;如果是后者大,就测试该属性。


classifyInstance

public double classifyInstance(Instance instance)
                        throws java.lang.Exception
Classifies an instance.

参数:
instance - the instance to classify
返回:
the classification for the instance
抛出:
java.lang.Exception - if instance can't be classified successfully

distributionForInstance

public final double[] distributionForInstance(Instance instance)
                                       throws java.lang.Exception
Returns class probabilities for an instance.

参数:
instance - the instance to calculate the class probabilities for
返回:
the class probabilities
抛出:
java.lang.Exception - if distribution can't be computed successfully

graphType

public int graphType()
Returns the type of graph this classifier represents.

返回:
Drawable.TREE

graph

public java.lang.String graph()
                       throws java.lang.Exception
Returns graph describing the tree.

返回:
the graph describing the tree
抛出:
java.lang.Exception - if graph can't be computed

prefix

public java.lang.String prefix()
                        throws java.lang.Exception
Returns tree in prefix order.

返回:
the tree in prefix order
抛出:
java.lang.Exception - if something goes wrong

toSource

public java.lang.String toSource(java.lang.String className)
                          throws java.lang.Exception
Returns tree as an if-then statement.

参数:
className - the name of the Java class
返回:
the tree as a Java if-then type statement
抛出:
java.lang.Exception - if something goes wrong

listOptions

public java.util.Enumeration<Option> listOptions()
Returns an enumeration describing the available options. Valid options are:

-U
Use unpruned tree.

-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. No subtree raising is performed.

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

-S
Don't perform subtree raising.

-L
Do not clean up after the tree has been built. -A
If set, Laplace smoothing is used for predicted probabilites.

-Q
The seed for reduced-error pruning.

返回:
an enumeration of all the available options. commented by Fan Min

setOptions

public void setOptions(java.lang.String[] options)
                throws java.lang.Exception
Parses a given list of options. Valid options are:

 -U
  Use unpruned tree.
 
 -C <pruning confidence>
  Set confidence threshold for pruning.
  (default 0.25)
 
 -M <minimum number of instances>
  Set minimum number of instances 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.
 
 -S
  Don't perform subtree raising.
 
 -L
  Do not clean up after the tree has been built.
 
 -A
  Laplace smoothing for predicted probabilities.
 
 -Q <seed>
  Seed for random data shuffling (default 1).
 

参数:
options - the list of options as an array of strings
抛出:
java.lang.Exception - if an option is not supported

getOptions

public java.lang.String[] getOptions()
Gets the current settings of the Classifier.

返回:
an array of strings suitable for passing to setOptions

seedTipText

public java.lang.String seedTipText()
Returns the tip text for this property

返回:
tip text for this property suitable for displaying in the explorer/experimenter gui

getSeed

public int getSeed()
Get the value of Seed.

返回:
Value of Seed.

setSeed

public void setSeed(int newSeed)
Set the value of Seed.

参数:
newSeed - Value to assign to Seed.

useLaplaceTipText

public java.lang.String useLaplaceTipText()
Returns the tip text for this property

返回:
tip text for this property suitable for displaying in the explorer/experimenter gui

getUseLaplace

public boolean getUseLaplace()
Get the value of useLaplace.

返回:
Value of useLaplace.

setUseLaplace

public void setUseLaplace(boolean paraUseLaplace)
Set the value of useLaplace.

参数:
paraUseLaplace - Value to assign to useLaplace.

toString

public java.lang.String toString()
Returns a description of the classifier.

返回:
a description of the classifier

toSummaryString

public java.lang.String toSummaryString()
Returns a superconcise version of the model

返回:
a summary of the model

measureTreeSize

public double measureTreeSize()
Returns the size of the tree

返回:
the size of the tree

measureNumLeaves

public double measureNumLeaves()
Returns the number of leaves

返回:
the number of leaves

measureNumRules

public double measureNumRules()
Returns the number of rules (same as number of leaves)

返回:
the number of rules

enumerateMeasures

public java.util.Enumeration<java.lang.String> enumerateMeasures()
Returns an enumeration of the additional measure names

返回:
an enumeration of the measure names

getMeasure

public double getMeasure(java.lang.String additionalMeasureName)
Returns the value of the named measure

参数:
additionalMeasureName - the name of the measure to query for its value
返回:
the value of the named measure
抛出:
java.lang.IllegalArgumentException - if the named measure is not supported

unprunedTipText

public java.lang.String unprunedTipText()
Returns the tip text for this property

返回:
tip text for this property suitable for displaying in the explorer/experimenter gui

getUnpruned

public boolean getUnpruned()
Get the value of unpruned.

返回:
Value of unpruned.

setUnpruned

public void setUnpruned(boolean v)
Set the value of unpruned. Turns reduced-error pruning off if set.

参数:
v - Value to assign to unpruned.

confidenceFactorTipText

public java.lang.String confidenceFactorTipText()
Returns the tip text for this property

返回:
tip text for this property suitable for displaying in the explorer/experimenter gui

getConfidenceFactor

public float getConfidenceFactor()
Get the value of CF.

返回:
Value of CF.

setConfidenceFactor

public void setConfidenceFactor(float v)
Set the value of CF.

参数:
v - Value to assign to CF.

minNumObjTipText

public java.lang.String minNumObjTipText()
Returns the tip text for this property

返回:
tip text for this property suitable for displaying in the explorer/experimenter gui

getMinNumObj

public int getMinNumObj()
Get the value of minNumObj.

返回:
Value of minNumObj.

setMinNumObj

public void setMinNumObj(int v)
Set the value of minNumObj.

参数:
v - Value to assign to minNumObj.

reducedErrorPruningTipText

public java.lang.String reducedErrorPruningTipText()
Returns the tip text for this property

返回:
tip text for this property suitable for displaying in the explorer/experimenter gui

getReducedErrorPruning

public boolean getReducedErrorPruning()
Get the value of reducedErrorPruning.

返回:
Value of reducedErrorPruning.

setReducedErrorPruning

public void setReducedErrorPruning(boolean v)
Set the value of reducedErrorPruning. Turns unpruned trees off if set.

参数:
v - Value to assign to reducedErrorPruning.

numFoldsTipText

public java.lang.String numFoldsTipText()
Returns the tip text for this property

返回:
tip text for this property suitable for displaying in the explorer/experimenter gui

getNumFolds

public int getNumFolds()
Get the value of numFolds.

返回:
Value of numFolds.

setNumFolds

public void setNumFolds(int v)
Set the value of numFolds.

参数:
v - Value to assign to numFolds.

binarySplitsTipText

public java.lang.String binarySplitsTipText()
Returns the tip text for this property

返回:
tip text for this property suitable for displaying in the explorer/experimenter gui

getBinarySplits

public boolean getBinarySplits()
Get the value of binarySplits.

返回:
Value of binarySplits.

setBinarySplits

public void setBinarySplits(boolean v)
Set the value of binarySplits.

参数:
v - Value to assign to binarySplits.

subtreeRaisingTipText

public java.lang.String subtreeRaisingTipText()
Returns the tip text for this property

返回:
tip text for this property suitable for displaying in the explorer/experimenter gui

getSubtreeRaising

public boolean getSubtreeRaising()
Get the value of subtreeRaising.

返回:
Value of subtreeRaising.

setSubtreeRaising

public void setSubtreeRaising(boolean v)
Set the value of subtreeRaising.

参数:
v - Value to assign to subtreeRaising.

saveInstanceDataTipText

public java.lang.String saveInstanceDataTipText()
Returns the tip text for this property

返回:
tip text for this property suitable for displaying in the explorer/experimenter gui

getSaveInstanceData

public boolean getSaveInstanceData()
Check whether instance data is to be saved.

返回:
true if instance data is saved

setSaveInstanceData

public void setSaveInstanceData(boolean v)
Set whether instance data is to be saved.

参数:
v - true if instance data is to be saved

getRevision

public java.lang.String getRevision()
Returns the revision string.

返回:
the revision

evaluate

public void evaluate()
Evaluate the generated decision tree.
Compute the average cost including the test cost and the misclassification cost of the decision tree.


computeCost

public double computeCost(coser.classifiers.trees.csj48.ClassifierTree paraTree)
Compute the cost of the decision tree.
Recursive method

返回:
The cost including test cost and misclassification cost of the subtree.

computeTestcost

public int computeTestcost(boolean[] paraTest)
Compute the test cost


setTestcostArray

public void setTestcostArray(int[] paraTestcostArray)
Set the test cost array


setMisclassificationCostMatrix

public void setMisclassificationCostMatrix(int[][] paraCostMatrix)
Set the misclassification cost matrix


main

public static void main(java.lang.String[] argv)
Main method for testing this class

参数:
argv - the commandline options