Class DecisionTree
- java.lang.Object
-
- Catalano.MachineLearning.Classification.DecisionTrees.DecisionTree
-
- All Implemented Interfaces:
- IClassifier, java.io.Serializable, java.lang.Cloneable
public class DecisionTree extends java.lang.Object implements IClassifier, java.io.Serializable
Decision tree for classification. A decision tree can be learned by splitting the training set into subsets based on an attribute value test. This process is repeated on each derived subset in a recursive manner called recursive partitioning. The recursion is completed when the subset at a node all has the same value of the target variable, or when splitting no longer adds value to the predictions.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.
- Simple to understand and interpret.
- In most cases, the interpretation of results summarized in a tree is very simple. This simplicity is useful not only for purposes of rapid classification of new observations, but can also often yield a much simpler "model" for explaining why observations are classified or predicted in a particular manner.
- Able to handle both numerical and categorical data.
- Other techniques are usually specialized in analyzing datasets that have only one type of variable.
- Tree methods are nonparametric and nonlinear.
- The final results of using tree methods for classification or regression can be summarized in a series of (usually few) logical if-then conditions (tree nodes). Therefore, there is no implicit assumption that the underlying relationships between the predictor variables and the dependent variable are linear, follow some specific non-linear link function, or that they are even monotonic in nature. Thus, tree methods are particularly well suited for data mining tasks, where there is often little a priori knowledge nor any coherent set of theories or predictions regarding which variables are related and how. In those types of data analytics, tree methods can often reveal simple relationships between just a few variables that could have easily gone unnoticed using other analytic techniques.
Some techniques such as bagging, boosting, and random forest use more than one decision tree for their analysis.
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class and Description static classDecisionTree.SplitRuleThe criterion to choose variable to split instances.
-
Constructor Summary
Constructors 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.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description IClassifierclone()Clone of the object.double[]getImportance()Returns the variable importance.intgetNumberOfLeafs()Get number maximum of leafs.DecisionTree.SplitRulegetRule()Get the split rule.voidLearn(DatasetClassification dataset)Learn from a dataset.voidLearn(double[][] input, int[] output)Learn.intPredict(double[] feature)Predict.voidsetNumberOfLeafs(int J)Set number maximum of leafs.voidsetRule(DecisionTree.SplitRule rule)Set the split rule
-
-
-
Constructor Detail
-
DecisionTree
public DecisionTree()
Initialize a new instance of the DecisionTree class. Learns a classification tree with (most) given number of leaves. All attributes are assumed to be numeric.
-
DecisionTree
public DecisionTree(int J)
Initialize a new instance of the DecisionTree class. Learns a classification tree with (most) given number of leaves. All attributes are assumed to be numeric.- Parameters:
J- the maximum number of leaf nodes in the tree.
-
DecisionTree
public DecisionTree(int J, DecisionTree.SplitRule rule)Initialize a new instance of the DecisionTree class. Learns a classification tree with (most) given number of leaves. All attributes are assumed to be numeric.- Parameters:
J- the maximum number of leaf nodes in the tree.rule- the splitting rule.
-
DecisionTree
public DecisionTree(DecisionVariable[] attributes)
Initialize a new instance of the DecisionTree class. Learns a classification tree with (most) given number of leaves.- Parameters:
attributes- the attribute properties.
-
DecisionTree
public DecisionTree(DecisionVariable[] attributes, int J)
Initialize a new instance of the DecisionTree class. Learns a classification tree with (most) given number of leaves.- Parameters:
attributes- the attribute properties.J- the maximum number of leaf nodes in the tree.
-
DecisionTree
public DecisionTree(DecisionVariable[] attributes, int J, DecisionTree.SplitRule rule)
Initialize a new instance of the DecisionTree class. Learns a classification tree with (most) given number of leaves.- Parameters:
attributes- the attribute properties.J- the maximum number of leaf nodes in the tree.rule- the splitting rule.
-
DecisionTree
public DecisionTree(DecisionVariable[] attributes, int J, int[] samples, int[][] order, DecisionTree.SplitRule rule)
Initialize a new instance of the DecisionTree class (AdaBoost). Learns a classification tree for AdaBoost.- Parameters:
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.
-
DecisionTree
public 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). Learns a classification tree for random forest.- Parameters:
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.
-
-
Method Detail
-
getImportance
public double[] getImportance()
Returns the variable importance. Every time a split of a node is made on variable the (GINI, information gain, etc.) impurity criterion for the two descendent nodes is less than the parent node. Adding up the decreases for each individual variable over the tree gives a simple measure of variable importance.- Returns:
- the variable importance
-
getNumberOfLeafs
public int getNumberOfLeafs()
Get number maximum of leafs.- Returns:
- Number of leafs.
-
setNumberOfLeafs
public void setNumberOfLeafs(int J)
Set number maximum of leafs.- Parameters:
J- Number of leafs.
-
getRule
public DecisionTree.SplitRule getRule()
Get the split rule.- Returns:
- Split rule.
-
setRule
public void setRule(DecisionTree.SplitRule rule)
Set the split rule- Parameters:
rule- Split rule.
-
Learn
public void Learn(DatasetClassification dataset)
Description copied from interface:IClassifierLearn from a dataset.- Specified by:
Learnin interfaceIClassifier- Parameters:
dataset- Dataset.
-
Learn
public void Learn(double[][] input, int[] output)Description copied from interface:IClassifierLearn.- Specified by:
Learnin interfaceIClassifier- Parameters:
input- Matrix of features.output- Labels.
-
Predict
public int Predict(double[] feature)
Description copied from interface:IClassifierPredict.- Specified by:
Predictin interfaceIClassifier- Parameters:
feature- Feature.- Returns:
- Label.
-
clone
public IClassifier clone()
Description copied from interface:IClassifierClone of the object.- Specified by:
clonein interfaceIClassifier- Overrides:
clonein classjava.lang.Object- Returns:
- A new copy of the object.
-
-
DataMelt 3.0 © DataMelt by jWork.ORG