Package org.apache.spark.mllib.tree
Class DecisionTree
Object
org.apache.spark.mllib.tree.DecisionTree
- All Implemented Interfaces:
- Serializable,- org.apache.spark.internal.Logging
A class which implements a decision tree learning algorithm for classification and regression.
 It supports both continuous and categorical features.
 
param: strategy The configuration parameters for the tree algorithm which specify the type of decision tree (classification or regression), feature type (continuous, categorical), depth of the tree, quantile calculation strategy, etc. param: seed Random seed.
- See Also:
- 
Nested Class SummaryNested classes/interfaces inherited from interface org.apache.spark.internal.Loggingorg.apache.spark.internal.Logging.LogStringContext, org.apache.spark.internal.Logging.SparkShellLoggingFilter
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionstatic org.apache.spark.internal.Logging.LogStringContextLogStringContext(scala.StringContext sc) static org.slf4j.Loggerstatic voidorg$apache$spark$internal$Logging$$log__$eq(org.slf4j.Logger x$1) run(RDD<LabeledPoint> input) Method to train a decision tree model over an RDDstatic DecisionTreeModeltrain(RDD<LabeledPoint> input, Strategy strategy) Method to train a decision tree model.static DecisionTreeModeltrain(RDD<LabeledPoint> input, scala.Enumeration.Value algo, Impurity impurity, int maxDepth) Method to train a decision tree model.static DecisionTreeModeltrain(RDD<LabeledPoint> input, scala.Enumeration.Value algo, Impurity impurity, int maxDepth, int numClasses) Method to train a decision tree model.static DecisionTreeModeltrain(RDD<LabeledPoint> input, scala.Enumeration.Value algo, Impurity impurity, int maxDepth, int numClasses, int maxBins, scala.Enumeration.Value quantileCalculationStrategy, scala.collection.immutable.Map<Object, Object> categoricalFeaturesInfo) Method to train a decision tree model.static DecisionTreeModeltrainClassifier(JavaRDD<LabeledPoint> input, int numClasses, Map<Integer, Integer> categoricalFeaturesInfo, String impurity, int maxDepth, int maxBins) Java-friendly API fororg.apache.spark.mllib.tree.DecisionTree.trainClassifierstatic DecisionTreeModeltrainClassifier(RDD<LabeledPoint> input, int numClasses, scala.collection.immutable.Map<Object, Object> categoricalFeaturesInfo, String impurity, int maxDepth, int maxBins) Method to train a decision tree model for binary or multiclass classification.static DecisionTreeModeltrainRegressor(JavaRDD<LabeledPoint> input, Map<Integer, Integer> categoricalFeaturesInfo, String impurity, int maxDepth, int maxBins) Java-friendly API fororg.apache.spark.mllib.tree.DecisionTree.trainRegressorstatic DecisionTreeModeltrainRegressor(RDD<LabeledPoint> input, scala.collection.immutable.Map<Object, Object> categoricalFeaturesInfo, String impurity, int maxDepth, int maxBins) Method to train a decision tree model for regression.Methods inherited from class java.lang.Objectequals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.spark.internal.LogginginitializeForcefully, 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- 
DecisionTree- Parameters:
- strategy- The configuration parameters for the tree algorithm which specify the type of decision tree (classification or regression), feature type (continuous, categorical), depth of the tree, quantile calculation strategy, etc.
 
 
- 
- 
Method Details- 
trainMethod to train a decision tree model. The method supports binary and multiclass classification and regression.- Parameters:
- input- Training dataset: RDD of- LabeledPoint. For classification, labels should take values {0, 1, ..., numClasses-1}. For regression, labels are real numbers.
- strategy- The configuration parameters for the tree algorithm which specify the type of decision tree (classification or regression), feature type (continuous, categorical), depth of the tree, quantile calculation strategy, etc.
- Returns:
- DecisionTreeModel that can be used for prediction.
- Note:
- Using org.apache.spark.mllib.tree.DecisionTree.trainClassifierandorg.apache.spark.mllib.tree.DecisionTree.trainRegressoris recommended to clearly separate classification and regression.
 
- 
trainpublic static DecisionTreeModel train(RDD<LabeledPoint> input, scala.Enumeration.Value algo, Impurity impurity, int maxDepth) Method to train a decision tree model. The method supports binary and multiclass classification and regression.- Parameters:
- input- Training dataset: RDD of- LabeledPoint. For classification, labels should take values {0, 1, ..., numClasses-1}. For regression, labels are real numbers.
- algo- Type of decision tree, either classification or regression.
- impurity- Criterion used for information gain calculation.
- maxDepth- Maximum depth of the tree (e.g. depth 0 means 1 leaf node, depth 1 means 1 internal node + 2 leaf nodes).
- Returns:
- DecisionTreeModel that can be used for prediction.
- Note:
- Using org.apache.spark.mllib.tree.DecisionTree.trainClassifierandorg.apache.spark.mllib.tree.DecisionTree.trainRegressoris recommended to clearly separate classification and regression.
 
- 
trainpublic static DecisionTreeModel train(RDD<LabeledPoint> input, scala.Enumeration.Value algo, Impurity impurity, int maxDepth, int numClasses) Method to train a decision tree model. The method supports binary and multiclass classification and regression.- Parameters:
- input- Training dataset: RDD of- LabeledPoint. For classification, labels should take values {0, 1, ..., numClasses-1}. For regression, labels are real numbers.
- algo- Type of decision tree, either classification or regression.
- impurity- Criterion used for information gain calculation.
- maxDepth- Maximum depth of the tree (e.g. depth 0 means 1 leaf node, depth 1 means 1 internal node + 2 leaf nodes).
- numClasses- Number of classes for classification. Default value of 2.
- Returns:
- DecisionTreeModel that can be used for prediction.
- Note:
- Using org.apache.spark.mllib.tree.DecisionTree.trainClassifierandorg.apache.spark.mllib.tree.DecisionTree.trainRegressoris recommended to clearly separate classification and regression.
 
- 
trainpublic static DecisionTreeModel train(RDD<LabeledPoint> input, scala.Enumeration.Value algo, Impurity impurity, int maxDepth, int numClasses, int maxBins, scala.Enumeration.Value quantileCalculationStrategy, scala.collection.immutable.Map<Object, Object> categoricalFeaturesInfo) Method to train a decision tree model. The method supports binary and multiclass classification and regression.- Parameters:
- input- Training dataset: RDD of- LabeledPoint. For classification, labels should take values {0, 1, ..., numClasses-1}. For regression, labels are real numbers.
- algo- Type of decision tree, either classification or regression.
- impurity- Criterion used for information gain calculation.
- maxDepth- Maximum depth of the tree (e.g. depth 0 means 1 leaf node, depth 1 means 1 internal node + 2 leaf nodes).
- numClasses- Number of classes for classification. Default value of 2.
- maxBins- Maximum number of bins used for splitting features.
- quantileCalculationStrategy- Algorithm for calculating quantiles.
- categoricalFeaturesInfo- Map storing arity of categorical features. An entry (n to k) indicates that feature n is categorical with k categories indexed from 0: {0, 1, ..., k-1}.
- Returns:
- DecisionTreeModel that can be used for prediction.
- Note:
- Using org.apache.spark.mllib.tree.DecisionTree.trainClassifierandorg.apache.spark.mllib.tree.DecisionTree.trainRegressoris recommended to clearly separate classification and regression.
 
- 
trainClassifierpublic static DecisionTreeModel trainClassifier(RDD<LabeledPoint> input, int numClasses, scala.collection.immutable.Map<Object, Object> categoricalFeaturesInfo, String impurity, int maxDepth, int maxBins) Method to train a decision tree model for binary or multiclass classification.- Parameters:
- input- Training dataset: RDD of- LabeledPoint. Labels should take values {0, 1, ..., numClasses-1}.
- numClasses- Number of classes for classification.
- categoricalFeaturesInfo- Map storing arity of categorical features. An entry (n to k) indicates that feature n is categorical with k categories indexed from 0: {0, 1, ..., k-1}.
- impurity- Criterion used for information gain calculation. Supported values: "gini" (recommended) or "entropy".
- maxDepth- Maximum depth of the tree (e.g. depth 0 means 1 leaf node, depth 1 means 1 internal node + 2 leaf nodes). (suggested value: 5)
- maxBins- Maximum number of bins used for splitting features. (suggested value: 32)
- Returns:
- DecisionTreeModel that can be used for prediction.
 
- 
trainClassifierpublic static DecisionTreeModel trainClassifier(JavaRDD<LabeledPoint> input, int numClasses, Map<Integer, Integer> categoricalFeaturesInfo, String impurity, int maxDepth, int maxBins) Java-friendly API fororg.apache.spark.mllib.tree.DecisionTree.trainClassifier- Parameters:
- input- (undocumented)
- numClasses- (undocumented)
- categoricalFeaturesInfo- (undocumented)
- impurity- (undocumented)
- maxDepth- (undocumented)
- maxBins- (undocumented)
- Returns:
- (undocumented)
 
- 
trainRegressorpublic static DecisionTreeModel trainRegressor(RDD<LabeledPoint> input, scala.collection.immutable.Map<Object, Object> categoricalFeaturesInfo, String impurity, int maxDepth, int maxBins) Method to train a decision tree model for regression.- Parameters:
- input- Training dataset: RDD of- LabeledPoint. Labels are real numbers.
- categoricalFeaturesInfo- Map storing arity of categorical features. An entry (n to k) indicates that feature n is categorical with k categories indexed from 0: {0, 1, ..., k-1}.
- impurity- Criterion used for information gain calculation. The only supported value for regression is "variance".
- maxDepth- Maximum depth of the tree (e.g. depth 0 means 1 leaf node, depth 1 means 1 internal node + 2 leaf nodes). (suggested value: 5)
- maxBins- Maximum number of bins used for splitting features. (suggested value: 32)
- Returns:
- DecisionTreeModel that can be used for prediction.
 
- 
trainRegressorpublic static DecisionTreeModel trainRegressor(JavaRDD<LabeledPoint> input, Map<Integer, Integer> categoricalFeaturesInfo, String impurity, int maxDepth, int maxBins) Java-friendly API fororg.apache.spark.mllib.tree.DecisionTree.trainRegressor- Parameters:
- input- (undocumented)
- categoricalFeaturesInfo- (undocumented)
- impurity- (undocumented)
- maxDepth- (undocumented)
- maxBins- (undocumented)
- Returns:
- (undocumented)
 
- 
org$apache$spark$internal$Logging$$log_public static org.slf4j.Logger org$apache$spark$internal$Logging$$log_()
- 
org$apache$spark$internal$Logging$$log__$eqpublic static void org$apache$spark$internal$Logging$$log__$eq(org.slf4j.Logger x$1) 
- 
LogStringContextpublic static org.apache.spark.internal.Logging.LogStringContext LogStringContext(scala.StringContext sc) 
- 
runMethod to train a decision tree model over an RDD- Parameters:
- input- Training data: RDD of- LabeledPoint.
- Returns:
- DecisionTreeModel that can be used for prediction.
 
 
-