public class DecisionTree extends java.lang.Object implements IClassifier, java.io.Serializable
The algorithms that are used for constructing decision trees usually work top-down by choosing a variable at each step that is the next best variable to use in splitting the set of items. "Best" is defined by how well the variable splits the set into homogeneous subsets that have the same value of the target variable. Different algorithms use different formulae for measuring "best". Used by the CART algorithm, Gini impurity is a measure of how often a randomly chosen element from the set would be incorrectly labeled if it were randomly labeled according to the distribution of labels in the subset. Gini impurity can be computed by summing the probability of each item being chosen times the probability of a mistake in categorizing that item. It reaches its minimum (zero) when all cases in the node fall into a single target category. Information gain is another popular measure, used by the ID3, C4.5 and C5.0 algorithms. Information gain is based on the concept of entropy used in information theory. For categorical variables with different number of levels, however, information gain are biased in favor of those attributes with more levels. Instead, one may employ the information gain ratio, which solves the drawback of information gain.
Classification and Regression Tree techniques have a number of advantages over many of those alternative techniques.
Some techniques such as bagging, boosting, and random forest use more than one decision tree for their analysis.
| Modifier and Type | Class and Description |
|---|---|
static class |
DecisionTree.SplitRule
The criterion to choose variable to split instances.
|
| Constructor and Description |
|---|
DecisionTree()
Initialize a new instance of the DecisionTree class.
|
DecisionTree(DecisionVariable[] attributes)
Initialize a new instance of the DecisionTree class.
|
DecisionTree(DecisionVariable[] attributes,
double[][] x,
int[] y,
int M,
int[] samples,
int[][] order,
DecisionTree.SplitRule rule)
Initialize a new instance of the DecisionTree class (Random Forest).
|
DecisionTree(DecisionVariable[] attributes,
int J)
Initialize a new instance of the DecisionTree class.
|
DecisionTree(DecisionVariable[] attributes,
int J,
DecisionTree.SplitRule rule)
Initialize a new instance of the DecisionTree class.
|
DecisionTree(DecisionVariable[] attributes,
int J,
int[] samples,
int[][] order,
DecisionTree.SplitRule rule)
Initialize a new instance of the DecisionTree class (AdaBoost).
|
DecisionTree(int J)
Initialize a new instance of the DecisionTree class.
|
DecisionTree(int J,
DecisionTree.SplitRule rule)
Initialize a new instance of the DecisionTree class.
|
| Modifier and Type | Method and Description |
|---|---|
IClassifier |
clone()
Clone of the object.
|
double[] |
getImportance()
Returns the variable importance.
|
int |
getNumberOfLeafs()
Get number maximum of leafs.
|
DecisionTree.SplitRule |
getRule()
Get the split rule.
|
void |
Learn(DatasetClassification dataset)
Learn from a dataset.
|
void |
Learn(double[][] input,
int[] output)
Learn.
|
int |
Predict(double[] feature)
Predict.
|
void |
setNumberOfLeafs(int J)
Set number maximum of leafs.
|
void |
setRule(DecisionTree.SplitRule rule)
Set the split rule
|
public DecisionTree()
public DecisionTree(int J)
J - the maximum number of leaf nodes in the tree.public DecisionTree(int J,
DecisionTree.SplitRule rule)
J - the maximum number of leaf nodes in the tree.rule - the splitting rule.public DecisionTree(DecisionVariable[] attributes)
attributes - the attribute properties.public DecisionTree(DecisionVariable[] attributes, int J)
attributes - the attribute properties.J - the maximum number of leaf nodes in the tree.public DecisionTree(DecisionVariable[] attributes, int J, DecisionTree.SplitRule rule)
attributes - the attribute properties.J - the maximum number of leaf nodes in the tree.rule - the splitting rule.public DecisionTree(DecisionVariable[] attributes, int J, int[] samples, int[][] order, DecisionTree.SplitRule rule)
attributes - the attribute properties.J - the maximum number of leaf nodes in the tree.order - the index of training values in ascending order. Note
that only numeric attributes need be sorted.samples - the sample set of instances for stochastic learning.
samples[i] is the number of sampling for instance i.rule - Split rule.public DecisionTree(DecisionVariable[] attributes, double[][] x, int[] y, int M, int[] samples, int[][] order, DecisionTree.SplitRule rule)
attributes - the attribute properties.x - the training instances.y - the response variable.M - the number of input variables to pick to split on at each
node. It seems that dim/3 give generally good performance, where dim
is the number of variables.order - the index of training values in ascending order. Note
that only numeric attributes need be sorted.samples - the sample set of instances for stochastic learning.
samples[i] is the number of sampling for instance i.public double[] getImportance()
public int getNumberOfLeafs()
public void setNumberOfLeafs(int J)
J - Number of leafs.public DecisionTree.SplitRule getRule()
public void setRule(DecisionTree.SplitRule rule)
rule - Split rule.public void Learn(DatasetClassification dataset)
IClassifierLearn in interface IClassifierdataset - Dataset.public void Learn(double[][] input,
int[] output)
IClassifierLearn in interface IClassifierinput - Matrix of features.output - Labels.public int Predict(double[] feature)
IClassifierPredict in interface IClassifierfeature - Feature.public IClassifier clone()
IClassifierclone in interface IClassifierclone in class java.lang.Object