Class Tree

java.lang.Object
com.imsl.datamining.decisionTree.Tree
All Implemented Interfaces:
Serializable, Cloneable

public class Tree extends Object implements Serializable, Cloneable
Serves as the root node of a decision tree and contains information about the relationship of child nodes.
See Also:
  • 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 - an int, the number of observations (rows) in the input data
      minObsAllowedInChild - an int, the number of observations necessary in all potential child nodes before a node may be split
      maxNumberOfCategories - an int, the maximum number of categories allowed for categorical predictor variables
      maxNumberOfNodes - an int, the maximum number of nodes allowed in the tree
      nClasses - an int, the number of classes assumed by the response variable, if the response variable is categorical
      nPreds - an int, the number of predictors used in the model
      varType - a PredictiveModel.VariableType array 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 - an int array containing the number of values of each predictor variable
      predType - a PredictiveModel.VariableType array containing the variable type of each predictor variable
      nyMissing - an int equal 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 - an int, the number of observations (rows) in the input data
      minObsAllowedInChild - an int, the number of observations necessary in all potential child nodes before a node may be split
      maxNumberOfCategories - an int, the maximum number of categories allowed for categorical predictor variables
      maxNumberOfNodes - an int, the maximum number of nodes allowed in the tree
      nClasses - an int, the number of classes assumed by the response variable, if the response variable is categorical
      nPreds - an int, the number of predictors used in the model
      varType - a PredictiveModel.VariableType array 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 - an int array containing the number of values of each predictor variable
      predType - a PredictiveModel.VariableType array containing the variable type of each predictor variable
      predIdx - an int array containing the column index of each predictor
      nyMissing - an int equal to the number of missing values in the response variable
  • Method Details

    • getNode

      public TreeNode getNode(int i)
      Returns a copy of the specified node of the decision tree.
      Parameters:
      i - an int that specifies the index of a TreeNode to be returned
      Returns:
      a TreeNode corresponding to the specified index
    • getTerminalNodeIndicators

      public boolean[] getTerminalNodeIndicators()
      Returns the terminal node indicator array.
      Returns:
      a boolean array indicating which nodes are terminal nodes and which are not. If true at index i, then the node at index i is a terminal node.
    • printTree

      public void printTree()
      Prints the tree structure.
    • getNodes

      public TreeNode[] getNodes()
      Returns nodes within a decision tree.
      Returns:
      a TreeNode array containing a copy of the TreeNodes 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 int specifying 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.DecisionTreeSurrogateMethod interface.

      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 int array containing the number of values of each predictor variable
    • getPredictorType

      public PredictiveModel.VariableType getPredictorType(int i)
      Returns the PredictiveModel.VariableType of a predictor variable.
      Parameters:
      i - an int, the index of the predictor
      Returns:
      a VariableType, the variable type of the predictor at index i
    • getResponseType

      public PredictiveModel.VariableType getResponseType()
      Returns the PredictiveModel.VariableType of 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 - an int specifying the index of the node
      Returns:
      a boolean, that if true, then the node at index i is a terminal node
    • clone

      protected Tree clone()
      Returns a clone of this object.
      Overrides:
      clone in class Object
      Returns:
      a Tree that is a copy of this object
    • getNodeAssigments

      public int[] getNodeAssigments(double[][] testData)
      Returns the node assignments for testData using the tree.

      The user must ensure that testData has the same number of columns, variable types, and variable column locations as the original training data.

      Parameters:
      testData - a double matrix
      Returns:
      an int array containing the node assignments for each row of the input matrix
    • getPredictions

      public double[] getPredictions(double[][] testData)
      Returns the predicted values on testData using the tree.

      The user must ensure that testData has the same number of columns, variable types, and variable column locations as the original training data.

      Parameters:
      testData - a double matrix
      Returns:
      an int array containing the node assignments for each row of the input matrix