Class DecisionTreeClassifier

All Implemented Interfaces:
Serializable, org.apache.spark.internal.Logging, ClassifierParams, ProbabilisticClassifierParams, Params, HasCheckpointInterval, HasFeaturesCol, HasLabelCol, HasPredictionCol, HasProbabilityCol, HasRawPredictionCol, HasSeed, HasThresholds, HasWeightCol, PredictorParams, DecisionTreeClassifierParams, DecisionTreeParams, TreeClassifierParams, DefaultParamsWritable, Identifiable, MLWritable

Decision tree learning algorithm (http://en.wikipedia.org/wiki/Decision_tree_learning) for classification. It supports both binary and multiclass labels, as well as both continuous and categorical features.
See Also:
  • Constructor Details

    • DecisionTreeClassifier

      public DecisionTreeClassifier(String uid)
    • DecisionTreeClassifier

      public DecisionTreeClassifier()
  • Method Details

    • supportedImpurities

      public static final String[] supportedImpurities()
      Accessor for supported impurities: entropy, gini
    • load

      public static DecisionTreeClassifier load(String path)
    • read

      public static MLReader<T> read()
    • impurity

      public final Param<String> impurity()
      Description copied from interface: TreeClassifierParams
      Criterion used for information gain calculation (case-insensitive). This impurity type is used in DecisionTreeClassifier and RandomForestClassifier, Supported: "entropy" and "gini". (default = gini)
      Specified by:
      impurity in interface TreeClassifierParams
      Returns:
      (undocumented)
    • leafCol

      public final Param<String> leafCol()
      Description copied from interface: DecisionTreeParams
      Leaf indices column name. Predicted leaf index of each instance in each tree by preorder. (default = "")
      Specified by:
      leafCol in interface DecisionTreeParams
      Returns:
      (undocumented)
    • maxDepth

      public final IntParam maxDepth()
      Description copied from interface: DecisionTreeParams
      Maximum depth of the tree (nonnegative). E.g., depth 0 means 1 leaf node; depth 1 means 1 internal node + 2 leaf nodes. (default = 5)
      Specified by:
      maxDepth in interface DecisionTreeParams
      Returns:
      (undocumented)
    • maxBins

      public final IntParam maxBins()
      Description copied from interface: DecisionTreeParams
      Maximum number of bins used for discretizing continuous features and for choosing how to split on features at each node. More bins give higher granularity. Must be at least 2 and at least number of categories in any categorical feature. (default = 32)
      Specified by:
      maxBins in interface DecisionTreeParams
      Returns:
      (undocumented)
    • minInstancesPerNode

      public final IntParam minInstancesPerNode()
      Description copied from interface: DecisionTreeParams
      Minimum number of instances each child must have after split. If a split causes the left or right child to have fewer than minInstancesPerNode, the split will be discarded as invalid. Must be at least 1. (default = 1)
      Specified by:
      minInstancesPerNode in interface DecisionTreeParams
      Returns:
      (undocumented)
    • minWeightFractionPerNode

      public final DoubleParam minWeightFractionPerNode()
      Description copied from interface: DecisionTreeParams
      Minimum fraction of the weighted sample count that each child must have after split. If a split causes the fraction of the total weight in the left or right child to be less than minWeightFractionPerNode, the split will be discarded as invalid. Should be in the interval [0.0, 0.5). (default = 0.0)
      Specified by:
      minWeightFractionPerNode in interface DecisionTreeParams
      Returns:
      (undocumented)
    • minInfoGain

      public final DoubleParam minInfoGain()
      Description copied from interface: DecisionTreeParams
      Minimum information gain for a split to be considered at a tree node. Should be at least 0.0. (default = 0.0)
      Specified by:
      minInfoGain in interface DecisionTreeParams
      Returns:
      (undocumented)
    • maxMemoryInMB

      public final IntParam maxMemoryInMB()
      Description copied from interface: DecisionTreeParams
      Maximum memory in MB allocated to histogram aggregation. If too small, then 1 node will be split per iteration, and its aggregates may exceed this size. (default = 256 MB)
      Specified by:
      maxMemoryInMB in interface DecisionTreeParams
      Returns:
      (undocumented)
    • cacheNodeIds

      public final BooleanParam cacheNodeIds()
      Description copied from interface: DecisionTreeParams
      If false, the algorithm will pass trees to executors to match instances with nodes. If true, the algorithm will cache node IDs for each instance. Caching can speed up training of deeper trees. Users can set how often should the cache be checkpointed or disable it by setting checkpointInterval. (default = false)
      Specified by:
      cacheNodeIds in interface DecisionTreeParams
      Returns:
      (undocumented)
    • weightCol

      public final Param<String> weightCol()
      Description copied from interface: HasWeightCol
      Param for weight column name. If this is not set or empty, we treat all instance weights as 1.0.
      Specified by:
      weightCol in interface HasWeightCol
      Returns:
      (undocumented)
    • seed

      public final LongParam seed()
      Description copied from interface: HasSeed
      Param for random seed.
      Specified by:
      seed in interface HasSeed
      Returns:
      (undocumented)
    • checkpointInterval

      public final IntParam checkpointInterval()
      Description copied from interface: HasCheckpointInterval
      Param for set checkpoint interval (&gt;= 1) or disable checkpoint (-1). E.g. 10 means that the cache will get checkpointed every 10 iterations. Note: this setting will be ignored if the checkpoint directory is not set in the SparkContext.
      Specified by:
      checkpointInterval in interface HasCheckpointInterval
      Returns:
      (undocumented)
    • uid

      public String uid()
      Description copied from interface: Identifiable
      An immutable unique ID for the object and its derivatives.
      Specified by:
      uid in interface Identifiable
      Returns:
      (undocumented)
    • setMaxDepth

      public DecisionTreeClassifier setMaxDepth(int value)
    • setMaxBins

      public DecisionTreeClassifier setMaxBins(int value)
    • setMinInstancesPerNode

      public DecisionTreeClassifier setMinInstancesPerNode(int value)
    • setMinWeightFractionPerNode

      public DecisionTreeClassifier setMinWeightFractionPerNode(double value)
    • setMinInfoGain

      public DecisionTreeClassifier setMinInfoGain(double value)
    • setMaxMemoryInMB

      public DecisionTreeClassifier setMaxMemoryInMB(int value)
    • setCacheNodeIds

      public DecisionTreeClassifier setCacheNodeIds(boolean value)
    • setCheckpointInterval

      public DecisionTreeClassifier setCheckpointInterval(int value)
      Specifies how often to checkpoint the cached node IDs. E.g. 10 means that the cache will get checkpointed every 10 iterations. This is only used if cacheNodeIds is true and if the checkpoint directory is set in SparkContext. Must be at least 1. (default = 10)
      Parameters:
      value - (undocumented)
      Returns:
      (undocumented)
    • setImpurity

      public DecisionTreeClassifier setImpurity(String value)
    • setSeed

      public DecisionTreeClassifier setSeed(long value)
    • setWeightCol

      public DecisionTreeClassifier setWeightCol(String value)
      Sets the value of param weightCol(). If this is not set or empty, we treat all instance weights as 1.0. Default is not set, so all instances have weight one.

      Parameters:
      value - (undocumented)
      Returns:
      (undocumented)
    • copy

      public DecisionTreeClassifier copy(ParamMap extra)
      Description copied from interface: Params
      Creates a copy of this instance with the same UID and some extra params. Subclasses should implement this method and set the return type properly. See defaultCopy().
      Specified by:
      copy in interface Params
      Specified by:
      copy in class Predictor<Vector,DecisionTreeClassifier,DecisionTreeClassificationModel>
      Parameters:
      extra - (undocumented)
      Returns:
      (undocumented)