Package com.imsl.datamining.decisionTree
Class Tree
java.lang.Object
com.imsl.datamining.decisionTree.Tree
- All Implemented Interfaces:
Serializable,Cloneable
Serves as the root node of a decision tree and contains information about the
relationship of child nodes.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionTree(int nRows, int minObsAllowedInChild, int maxNumberOfCategories, int maxNumberOfNodes, int nClasses, int nPreds, PredictiveModel.VariableType varType, int[] predNValues, PredictiveModel.VariableType[] predType, int nyMissing) Deprecated.Update to the other constructor that accepts the predictor indices in argument 10.Tree(int nRows, int minObsAllowedInChild, int maxNumberOfCategories, int maxNumberOfNodes, int nClasses, int nPreds, PredictiveModel.VariableType varType, int[] predNValues, PredictiveModel.VariableType[] predType, int[] predIdx, int nyMissing) Creates the root node of a decision tree and contains information about the relationship of child nodes. -
Method Summary
Modifier and TypeMethodDescriptionprotected Treeclone()Returns a clone of this object.getNode(int i) Returns a copy of the specified node of the decision tree.int[]getNodeAssigments(double[][] testData) Returns the node assignments fortestDatausing the tree.TreeNode[]getNodes()Returns nodes within a decision tree.intReturns the number of classes assumed by the response variable, if the response variable is categorical.intReturns the number of levels or depth of a tree.intReturns the number of nodes (size of a tree).intReturns the number of predictors used in the model.intReturns the number of surrogate splits searched for at each tree node.double[]getPredictions(double[][] testData) Returns the predicted values ontestDatausing the tree.int[]Returns the number of distinct values of each predictor variable.getPredictorType(int i) Returns thePredictiveModel.VariableTypeof a predictor variable.Returns thePredictiveModel.VariableTypeof the response variable.boolean[]Returns the terminal node indicator array.booleanisTerminalNode(int i) Returns the terminal node indicator of the node at the given index.voidPrints the tree structure.
-
Constructor Details
-
Tree
public Tree(int nRows, int minObsAllowedInChild, int maxNumberOfCategories, int maxNumberOfNodes, int nClasses, int nPreds, PredictiveModel.VariableType varType, int[] predNValues, PredictiveModel.VariableType[] predType, int nyMissing) Deprecated.Update to the other constructor that accepts the predictor indices in argument 10. Creates the root node of a decision tree and contains information about the relationship of child nodes.- Parameters:
nRows- anint, the number of observations (rows) in the input dataminObsAllowedInChild- anint, the number of observations necessary in all potential child nodes before a node may be splitmaxNumberOfCategories- anint, the maximum number of categories allowed for categorical predictor variablesmaxNumberOfNodes- anint, the maximum number of nodes allowed in the treenClasses- anint, the number of classes assumed by the response variable, if the response variable is categoricalnPreds- anint, the number of predictors used in the modelvarType- aPredictiveModel.VariableTypearray of length equal to the number of variables active in the model, which is less than or equal to the available columns in the data, (xy[i].length)predNValues- anintarray containing the number of values of each predictor variablepredType- aPredictiveModel.VariableTypearray containing the variable type of each predictor variablenyMissing- anintequal to the number of missing values in the response variable
-
Tree
public Tree(int nRows, int minObsAllowedInChild, int maxNumberOfCategories, int maxNumberOfNodes, int nClasses, int nPreds, PredictiveModel.VariableType varType, int[] predNValues, PredictiveModel.VariableType[] predType, int[] predIdx, int nyMissing) Creates the root node of a decision tree and contains information about the relationship of child nodes.- Parameters:
nRows- anint, the number of observations (rows) in the input dataminObsAllowedInChild- anint, the number of observations necessary in all potential child nodes before a node may be splitmaxNumberOfCategories- anint, the maximum number of categories allowed for categorical predictor variablesmaxNumberOfNodes- anint, the maximum number of nodes allowed in the treenClasses- anint, the number of classes assumed by the response variable, if the response variable is categoricalnPreds- anint, the number of predictors used in the modelvarType- aPredictiveModel.VariableTypearray of length equal to the number of variables active in the model, which is less than or equal to the available columns in the data, (xy[i].length)predNValues- anintarray containing the number of values of each predictor variablepredType- aPredictiveModel.VariableTypearray containing the variable type of each predictor variablepredIdx- anintarray containing the column index of each predictornyMissing- anintequal to the number of missing values in the response variable
-
-
Method Details
-
getNode
Returns a copy of the specified node of the decision tree.- Parameters:
i- anintthat specifies the index of aTreeNodeto be returned- Returns:
- a
TreeNodecorresponding to the specified index
-
getTerminalNodeIndicators
public boolean[] getTerminalNodeIndicators()Returns the terminal node indicator array.- Returns:
- a
booleanarray indicating which nodes are terminal nodes and which are not. Iftrueat indexi, then the node at indexiis a terminal node.
-
printTree
public void printTree()Prints the tree structure. -
getNodes
Returns nodes within a decision tree.- Returns:
- a
TreeNodearray containing a copy of theTreeNodes within the decision tree
-
getNumberOfClasses
public int getNumberOfClasses()Returns the number of classes assumed by the response variable, if the response variable is categorical.- Returns:
- an
int, the number of classes assumed by the response variable, if the response variable is categorical
-
getNumberOfLevels
public int getNumberOfLevels()Returns the number of levels or depth of a tree.- Returns:
- an
intspecifying the number of levels or depth of a tree
-
getNumberOfNodes
public int getNumberOfNodes()Returns the number of nodes (size of a tree).- Returns:
- an
int, the number of nodes or size of the tree
-
getNumberOfPredictors
public int getNumberOfPredictors()Returns the number of predictors used in the model.- Returns:
- an
int, the number of predictors used in the model
-
getNumberOfSurrogateSplits
public int getNumberOfSurrogateSplits()Returns the number of surrogate splits searched for at each tree node.Surrogate splits are relevant only for classes that implement the
com.imsl.datamining.decisionTree.DecisionTreeSurrogateMethodinterface.- Returns:
- an
int, the number of surrogate splits searched for at each node
-
getPredictorNumberOfValues
public int[] getPredictorNumberOfValues()Returns the number of distinct values of each predictor variable.For continuous predictor variables, the value is set to 0 and is not meaningful.
- Returns:
- an
intarray containing the number of values of each predictor variable
-
getPredictorType
Returns thePredictiveModel.VariableTypeof a predictor variable.- Parameters:
i- anint, the index of the predictor- Returns:
- a
VariableType, the variable type of the predictor at indexi
-
getResponseType
Returns thePredictiveModel.VariableTypeof the response variable.- Returns:
- a
PredictiveModel.VariableType, indicates the response variable type
-
isTerminalNode
public boolean isTerminalNode(int i) Returns the terminal node indicator of the node at the given index.- Parameters:
i- anintspecifying the index of the node- Returns:
- a
boolean, that iftrue, then the node at indexiis a terminal node
-
clone
Returns a clone of this object. -
getNodeAssigments
public int[] getNodeAssigments(double[][] testData) Returns the node assignments fortestDatausing the tree.The user must ensure that
testDatahas the same number of columns, variable types, and variable column locations as the original training data.- Parameters:
testData- adoublematrix- Returns:
- an
intarray containing the node assignments for each row of the input matrix
-
getPredictions
public double[] getPredictions(double[][] testData) Returns the predicted values ontestDatausing the tree.The user must ensure that
testDatahas the same number of columns, variable types, and variable column locations as the original training data.- Parameters:
testData- adoublematrix- Returns:
- an
intarray containing the node assignments for each row of the input matrix
-