public class RandomTree extends Classifier implements OptionHandler, WeightedInstancesHandler, Randomizable, Drawable
-K <number of attributes> Number of attributes to randomly investigate (<0 = int(log_2(#attributes)+1)).
-M <minimum number of instances> Set minimum number of instances per leaf.
-S <num> Seed for random number generator. (default 1)
-depth <num> The maximum depth of the tree, 0 for unlimited. (default 0)
-N <num> Number of folds for backfitting (default 0, no backfitting).
-U Allow unclassified instances.
-D If set, classifier is run in debug mode and may output additional info to the console
Modifier and Type | Field and Description |
---|---|
protected boolean |
m_AllowUnclassifiedInstances
Whether unclassified instances are allowed
|
protected int |
m_Attribute
The attribute to split on.
|
protected double[] |
m_ClassDistribution
Class probabilities from the training data.
|
protected Instances |
m_Info
The header information.
|
protected int |
m_KValue
The number of attributes considered for a split.
|
protected int |
m_MaxDepth
The maximum depth of the tree (0 = unlimited)
|
protected double |
m_MinNum
Minimum number of instances for leaf.
|
protected int |
m_NumFolds
Determines how much data is used for backfitting
|
protected double[] |
m_Prop
The proportions of training instances going down each branch.
|
protected int |
m_randomSeed
The random seed to use.
|
protected double |
m_SplitPoint
The split point.
|
protected RandomTree[] |
m_Successors
The subtrees appended to this tree.
|
protected Classifier |
m_ZeroR
a ZeroR model in case no model can be built from the data
|
m_Debug
BayesNet, Newick, NOT_DRAWABLE, TREE
Constructor and Description |
---|
RandomTree() |
Modifier and Type | Method and Description |
---|---|
String |
allowUnclassifiedInstancesTipText()
Returns the tip text for this property
|
void |
backfitData(Instances data)
Backfits the given data into the tree.
|
protected void |
backfitData(Instances data,
double[] classProbs)
Recursively backfits data into the tree.
|
void |
buildClassifier(Instances data)
Builds classifier.
|
protected void |
buildTree(Instances data,
double[] classProbs,
Instances header,
double minNum,
boolean debug,
int[] attIndicesWindow,
Random random,
int depth,
boolean allow)
Recursively generates a tree.
|
protected double |
distribution(double[][] props,
double[][][] dists,
int att,
Instances data)
Computes class distribution for an attribute.
|
double[] |
distributionForInstance(Instance instance)
Computes class distribution of an instance using the decision tree.
|
protected double |
gain(double[][] dist,
double priorVal)
Computes value of splitting criterion after split.
|
boolean |
getAllowUnclassifiedInstances()
Get the value of NumFolds.
|
Capabilities |
getCapabilities()
Returns default capabilities of the classifier.
|
int |
getKValue()
Get the value of K.
|
int |
getMaxDepth()
Get the maximum depth of trh tree, 0 for unlimited.
|
double |
getMinNum()
Get the value of MinNum.
|
int |
getNumFolds()
Get the value of NumFolds.
|
String[] |
getOptions()
Gets options from this classifier.
|
String |
getRevision()
Returns the revision string.
|
int |
getSeed()
Gets the seed for the random number generations
|
String |
globalInfo()
Returns a string describing classifier
|
String |
graph()
Returns graph describing the tree.
|
int |
graphType()
Returns the type of graph this classifier represents.
|
String |
KValueTipText()
Returns the tip text for this property
|
protected String |
leafString()
Outputs a leaf.
|
Enumeration |
listOptions()
Lists the command-line options for this classifier.
|
static void |
main(String[] argv)
Main method for this class.
|
String |
maxDepthTipText()
Returns the tip text for this property
|
String |
minNumTipText()
Returns the tip text for this property
|
String |
numFoldsTipText()
Returns the tip text for this property
|
int |
numNodes()
Computes size of the tree.
|
protected double |
priorVal(double[][] dist)
Computes value of splitting criterion before split.
|
String |
seedTipText()
Returns the tip text for this property
|
void |
setAllowUnclassifiedInstances(boolean newAllowUnclassifiedInstances)
Set the value of AllowUnclassifiedInstances.
|
void |
setKValue(int k)
Set the value of K.
|
void |
setMaxDepth(int value)
Set the maximum depth of the tree, 0 for unlimited.
|
void |
setMinNum(double newMinNum)
Set the value of MinNum.
|
void |
setNumFolds(int newNumFolds)
Set the value of NumFolds.
|
void |
setOptions(String[] options)
Parses a given list of options.
|
void |
setSeed(int seed)
Set the seed for random number generation.
|
protected Instances[] |
splitData(Instances data)
Splits instances into subsets based on the given split.
|
String |
toGraph()
Outputs the decision tree as a graph
|
int |
toGraph(StringBuffer text,
int num)
Outputs one node for graph.
|
protected int |
toGraph(StringBuffer text,
int num,
RandomTree parent)
Outputs one node for graph.
|
String |
toString()
Outputs the decision tree.
|
protected String |
toString(int level)
Recursively outputs the tree.
|
classifyInstance, debugTipText, forName, getDebug, makeCopies, makeCopy, runClassifier, setDebug
protected RandomTree[] m_Successors
protected int m_Attribute
protected double m_SplitPoint
protected Instances m_Info
protected double[] m_Prop
protected double[] m_ClassDistribution
protected double m_MinNum
protected int m_KValue
protected int m_randomSeed
protected int m_MaxDepth
protected int m_NumFolds
protected boolean m_AllowUnclassifiedInstances
protected Classifier m_ZeroR
public String globalInfo()
public String minNumTipText()
public double getMinNum()
public void setMinNum(double newMinNum)
newMinNum
- Value to assign to MinNum.public String KValueTipText()
public int getKValue()
public void setKValue(int k)
k
- Value to assign to K.public String seedTipText()
public void setSeed(int seed)
setSeed
in interface Randomizable
seed
- the seedpublic int getSeed()
getSeed
in interface Randomizable
public String maxDepthTipText()
public int getMaxDepth()
public String numFoldsTipText()
public int getNumFolds()
public void setNumFolds(int newNumFolds)
newNumFolds
- Value to assign to NumFolds.public String allowUnclassifiedInstancesTipText()
public boolean getAllowUnclassifiedInstances()
public void setAllowUnclassifiedInstances(boolean newAllowUnclassifiedInstances)
newAllowUnclassifiedInstances
- Value to assign to AllowUnclassifiedInstances.public void setMaxDepth(int value)
value
- the maximum depth.public Enumeration listOptions()
listOptions
in interface OptionHandler
listOptions
in class Classifier
public String[] getOptions()
getOptions
in interface OptionHandler
getOptions
in class Classifier
public void setOptions(String[] options) throws Exception
-K <number of attributes> Number of attributes to randomly investigate (<0 = int(log_2(#attributes)+1)).
-M <minimum number of instances> Set minimum number of instances per leaf.
-S <num> Seed for random number generator. (default 1)
-depth <num> The maximum depth of the tree, 0 for unlimited. (default 0)
-N <num> Number of folds for backfitting (default 0, no backfitting).
-U Allow unclassified instances.
-D If set, classifier is run in debug mode and may output additional info to the console
setOptions
in interface OptionHandler
setOptions
in class Classifier
options
- the list of options as an array of stringsException
- if an option is not supportedpublic Capabilities getCapabilities()
getCapabilities
in interface CapabilitiesHandler
getCapabilities
in class Classifier
Capabilities
public void buildClassifier(Instances data) throws Exception
buildClassifier
in class Classifier
data
- the data to train withException
- if something goes wrong or the data doesn't fitpublic void backfitData(Instances data) throws Exception
Exception
public double[] distributionForInstance(Instance instance) throws Exception
distributionForInstance
in class Classifier
instance
- the instance to compute the distribution forException
- if computation failspublic String toGraph()
public int toGraph(StringBuffer text, int num) throws Exception
text
- the buffer to append the output tonum
- unique node idException
- if generation failspublic String toString()
protected String leafString() throws Exception
Exception
- if generation failsprotected String toString(int level)
level
- the current level of the treeprotected void backfitData(Instances data, double[] classProbs) throws Exception
data
- the data to work withclassProbs
- the class distributionException
- if generation failsprotected void buildTree(Instances data, double[] classProbs, Instances header, double minNum, boolean debug, int[] attIndicesWindow, Random random, int depth, boolean allow) throws Exception
data
- the data to work withclassProbs
- the class distributionheader
- the header of the dataminNum
- the minimum number of instances per leafdebug
- whether debugging is onattIndicesWindow
- the attribute window to choose attributes fromrandom
- random number generator for choosing random attributesdepth
- the current depthdetermineStructure
- whether to determine structureException
- if generation failspublic int numNodes()
protected Instances[] splitData(Instances data) throws Exception
data
- the data to work withException
- if something goes wrongprotected double distribution(double[][] props, double[][][] dists, int att, Instances data) throws Exception
props
- dists
- att
- the attribute indexdata
- the data to work withException
- if something goes wrongprotected double priorVal(double[][] dist)
dist
- the distributionsprotected double gain(double[][] dist, double priorVal)
dist
- the distributionspriorVal
- the splitting criterionpublic String getRevision()
getRevision
in interface RevisionHandler
getRevision
in class Classifier
public static void main(String[] argv)
argv
- the commandline parameterspublic int graphType()
protected int toGraph(StringBuffer text, int num, RandomTree parent) throws Exception
text
- the buffer to append the output tonum
- the current node idparent
- the parent of the nodesException
- if something goes wrongCopyright © 2015 University of Waikato, Hamilton, NZ. All rights reserved.