Class Node

Object
org.apache.spark.mllib.tree.model.Node
All Implemented Interfaces:
Serializable, org.apache.spark.internal.Logging

public class Node extends Object implements Serializable, org.apache.spark.internal.Logging
Node in a decision tree.

About node indexing: Nodes are indexed from 1. Node 1 is the root; nodes 2, 3 are the left, right children. Node index 0 is not used.

param: id integer node id, from 1 param: predict predicted value at the node param: impurity current node impurity param: isLeaf whether the node is a leaf param: split split to calculate left and right nodes param: leftNode left child param: rightNode right child param: stats information gain stats

See Also:
  • Nested Class Summary

    Nested classes/interfaces inherited from interface org.apache.spark.internal.Logging

    org.apache.spark.internal.Logging.LogStringContext, org.apache.spark.internal.Logging.SparkShellLoggingFilter
  • Constructor Summary

    Constructors
    Constructor
    Description
    Node(int id, Predict predict, double impurity, boolean isLeaf, scala.Option<Split> split, scala.Option<Node> leftNode, scala.Option<Node> rightNode, scala.Option<InformationGainStats> stats)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static Node
    apply(int nodeIndex, Predict predict, double impurity, boolean isLeaf)
    Construct a node with nodeIndex, predict, impurity and isLeaf parameters.
    int
    id()
     
    double
     
    boolean
     
    static int
    leftChildIndex(int nodeIndex)
    Return the index of the left child of this node.
    scala.Option<Node>
     
     
    double
    predict(Vector features)
    predict value if node is not leaf
    static int
    rightChildIndex(int nodeIndex)
    Return the index of the right child of this node.
    scala.Option<Node>
     
    scala.Option<Split>
     
    scala.Option<InformationGainStats>
     
     

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface org.apache.spark.internal.Logging

    initializeForcefully, initializeLogIfNecessary, initializeLogIfNecessary, initializeLogIfNecessary$default$2, isTraceEnabled, log, logBasedOnLevel, logDebug, logDebug, logDebug, logDebug, logError, logError, logError, logError, logInfo, logInfo, logInfo, logInfo, logName, LogStringContext, logTrace, logTrace, logTrace, logTrace, logWarning, logWarning, logWarning, logWarning, MDC, org$apache$spark$internal$Logging$$log_, org$apache$spark$internal$Logging$$log__$eq, withLogContext
  • Constructor Details

    • Node

      public Node(int id, Predict predict, double impurity, boolean isLeaf, scala.Option<Split> split, scala.Option<Node> leftNode, scala.Option<Node> rightNode, scala.Option<InformationGainStats> stats)
  • Method Details

    • apply

      public static Node apply(int nodeIndex, Predict predict, double impurity, boolean isLeaf)
      Construct a node with nodeIndex, predict, impurity and isLeaf parameters. This is used in DecisionTree.findBestSplits to construct child nodes after finding the best splits for parent nodes. Other fields are set at next level.
      Parameters:
      nodeIndex - integer node id, from 1
      predict - predicted value at the node
      impurity - current node impurity
      isLeaf - whether the node is a leaf
      Returns:
      new node instance
    • leftChildIndex

      public static int leftChildIndex(int nodeIndex)
      Return the index of the left child of this node.
      Parameters:
      nodeIndex - (undocumented)
      Returns:
      (undocumented)
    • rightChildIndex

      public static int rightChildIndex(int nodeIndex)
      Return the index of the right child of this node.
      Parameters:
      nodeIndex - (undocumented)
      Returns:
      (undocumented)
    • id

      public int id()
    • predict

      public Predict predict()
    • impurity

      public double impurity()
    • isLeaf

      public boolean isLeaf()
    • split

      public scala.Option<Split> split()
    • leftNode

      public scala.Option<Node> leftNode()
    • rightNode

      public scala.Option<Node> rightNode()
    • stats

      public scala.Option<InformationGainStats> stats()
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • predict

      public double predict(Vector features)
      predict value if node is not leaf
      Parameters:
      features - feature value
      Returns:
      predicted value