Package org.apache.spark.ml.regression
Class DecisionTreeRegressionModel
Object
org.apache.spark.ml.PipelineStage
org.apache.spark.ml.Transformer
org.apache.spark.ml.Model<M>
org.apache.spark.ml.PredictionModel<FeaturesType,M>
org.apache.spark.ml.regression.RegressionModel<Vector,DecisionTreeRegressionModel>
org.apache.spark.ml.regression.DecisionTreeRegressionModel
- All Implemented Interfaces:
Serializable
,org.apache.spark.internal.Logging
,Params
,HasCheckpointInterval
,HasFeaturesCol
,HasLabelCol
,HasPredictionCol
,HasSeed
,HasVarianceCol
,HasWeightCol
,PredictorParams
,DecisionTreeModel
,DecisionTreeParams
,DecisionTreeRegressorParams
,HasVarianceImpurity
,TreeRegressorParams
,Identifiable
,MLWritable
public class DecisionTreeRegressionModel
extends RegressionModel<Vector,DecisionTreeRegressionModel>
implements DecisionTreeModel, DecisionTreeRegressorParams, MLWritable, Serializable
Decision tree (Wikipedia) model for regression.
It supports both continuous and categorical features.
param: rootNode Root of the decision tree
- 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
-
Method Summary
Modifier and TypeMethodDescriptionfinal BooleanParam
If false, the algorithm will pass trees to executors to match instances with nodes.final IntParam
Param for set checkpoint interval (>= 1) or disable checkpoint (-1).Creates a copy of this instance with the same UID and some extra params.int
depth()
Depth of the tree.impurity()
Criterion used for information gain calculation (case-insensitive).leafCol()
Leaf indices column name.static DecisionTreeRegressionModel
final IntParam
maxBins()
Maximum number of bins used for discretizing continuous features and for choosing how to split on features at each node.final IntParam
maxDepth()
Maximum depth of the tree (nonnegative).final IntParam
Maximum memory in MB allocated to histogram aggregation.final DoubleParam
Minimum information gain for a split to be considered at a tree node.final IntParam
Minimum number of instances each child must have after split.final DoubleParam
Minimum fraction of the weighted sample count that each child must have after split.int
Returns the number of features the model was trained on.double
Predict label for the given features.static MLReader<DecisionTreeRegressionModel>
read()
rootNode()
Root of the decision treefinal LongParam
seed()
Param for random seed.setVarianceCol
(String value) toString()
Summary of the modelTransforms dataset by reading fromPredictionModel.featuresCol()
, callingpredict
, and storing the predictions as a new columnPredictionModel.predictionCol()
.transformSchema
(StructType schema) Check transform validity and derive the output schema from the input schema.uid()
An immutable unique ID for the object and its derivatives.Param for Column name for the biased sample variance of prediction.Param for weight column name.write()
Returns anMLWriter
instance for this ML instance.Methods inherited from class org.apache.spark.ml.PredictionModel
featuresCol, labelCol, predictionCol, setFeaturesCol, setPredictionCol
Methods inherited from class org.apache.spark.ml.Transformer
transform, transform, transform
Methods inherited from class org.apache.spark.ml.PipelineStage
params
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.apache.spark.ml.tree.DecisionTreeModel
getLeafField, leafIterator, maxSplitFeatureIndex, numNodes, predictLeaf, toDebugString
Methods inherited from interface org.apache.spark.ml.tree.DecisionTreeParams
getCacheNodeIds, getLeafCol, getMaxBins, getMaxDepth, getMaxMemoryInMB, getMinInfoGain, getMinInstancesPerNode, getMinWeightFractionPerNode, getOldStrategy, setLeafCol
Methods inherited from interface org.apache.spark.ml.tree.DecisionTreeRegressorParams
validateAndTransformSchema
Methods inherited from interface org.apache.spark.ml.param.shared.HasCheckpointInterval
getCheckpointInterval
Methods inherited from interface org.apache.spark.ml.param.shared.HasFeaturesCol
featuresCol, getFeaturesCol
Methods inherited from interface org.apache.spark.ml.param.shared.HasLabelCol
getLabelCol, labelCol
Methods inherited from interface org.apache.spark.ml.param.shared.HasPredictionCol
getPredictionCol, predictionCol
Methods inherited from interface org.apache.spark.ml.param.shared.HasVarianceCol
getVarianceCol
Methods inherited from interface org.apache.spark.ml.tree.HasVarianceImpurity
getImpurity, getOldImpurity
Methods inherited from interface org.apache.spark.ml.param.shared.HasWeightCol
getWeightCol
Methods inherited from interface org.apache.spark.internal.Logging
initializeForcefully, initializeLogIfNecessary, initializeLogIfNecessary, initializeLogIfNecessary$default$2, isTraceEnabled, log, logDebug, logDebug, logDebug, logDebug, logError, logError, logError, logError, logInfo, logInfo, logInfo, logInfo, logName, LogStringContext, logTrace, logTrace, logTrace, logTrace, logWarning, logWarning, logWarning, logWarning, org$apache$spark$internal$Logging$$log_, org$apache$spark$internal$Logging$$log__$eq, withLogContext
Methods inherited from interface org.apache.spark.ml.util.MLWritable
save
Methods inherited from interface org.apache.spark.ml.param.Params
clear, copyValues, defaultCopy, defaultParamMap, explainParam, explainParams, extractParamMap, extractParamMap, get, getDefault, getOrDefault, getParam, hasDefault, hasParam, isDefined, isSet, onParamChange, paramMap, params, set, set, set, setDefault, setDefault, shouldOwn
-
Method Details
-
read
-
load
-
varianceCol
Description copied from interface:HasVarianceCol
Param for Column name for the biased sample variance of prediction.- Specified by:
varianceCol
in interfaceHasVarianceCol
- Returns:
- (undocumented)
-
impurity
Description copied from interface:HasVarianceImpurity
Criterion used for information gain calculation (case-insensitive). This impurity type is used in DecisionTreeRegressor, RandomForestRegressor, GBTRegressor and GBTClassifier (since GBTClassificationModel is internally composed of DecisionTreeRegressionModels). Supported: "variance". (default = variance)- Specified by:
impurity
in interfaceHasVarianceImpurity
- Returns:
- (undocumented)
-
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 interfaceDecisionTreeParams
- Returns:
- (undocumented)
-
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 interfaceDecisionTreeParams
- Returns:
- (undocumented)
-
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 interfaceDecisionTreeParams
- Returns:
- (undocumented)
-
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 interfaceDecisionTreeParams
- Returns:
- (undocumented)
-
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 interfaceDecisionTreeParams
- Returns:
- (undocumented)
-
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 interfaceDecisionTreeParams
- Returns:
- (undocumented)
-
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 interfaceDecisionTreeParams
- Returns:
- (undocumented)
-
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 interfaceDecisionTreeParams
- Returns:
- (undocumented)
-
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 interfaceHasWeightCol
- Returns:
- (undocumented)
-
seed
Description copied from interface:HasSeed
Param for random seed. -
checkpointInterval
Description copied from interface:HasCheckpointInterval
Param for set checkpoint interval (>= 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 interfaceHasCheckpointInterval
- Returns:
- (undocumented)
-
depth
public int depth()Description copied from interface:DecisionTreeModel
Depth of the tree. E.g.: Depth 0 means 1 leaf node. Depth 1 means 1 internal node and 2 leaf nodes.- Specified by:
depth
in interfaceDecisionTreeModel
- Returns:
- (undocumented)
-
uid
Description copied from interface:Identifiable
An immutable unique ID for the object and its derivatives.- Specified by:
uid
in interfaceIdentifiable
- Returns:
- (undocumented)
-
rootNode
Description copied from interface:DecisionTreeModel
Root of the decision tree- Specified by:
rootNode
in interfaceDecisionTreeModel
-
numFeatures
public int numFeatures()Description copied from class:PredictionModel
Returns the number of features the model was trained on. If unknown, returns -1- Overrides:
numFeatures
in classPredictionModel<Vector,
DecisionTreeRegressionModel>
-
setVarianceCol
-
predict
Description copied from class:PredictionModel
Predict label for the given features. This method is used to implementtransform()
and outputPredictionModel.predictionCol()
.- Specified by:
predict
in classPredictionModel<Vector,
DecisionTreeRegressionModel> - Parameters:
features
- (undocumented)- Returns:
- (undocumented)
-
transformSchema
Description copied from class:PipelineStage
Check transform validity and derive the output schema from the input schema.We check validity for interactions between parameters during
transformSchema
and raise an exception if any parameter value is invalid. Parameter value checks which do not depend on other parameters are handled byParam.validate()
.Typical implementation should first conduct verification on schema change and parameter validity, including complex parameter interaction checks.
- Overrides:
transformSchema
in classPredictionModel<Vector,
DecisionTreeRegressionModel> - Parameters:
schema
- (undocumented)- Returns:
- (undocumented)
-
transform
Description copied from class:PredictionModel
Transforms dataset by reading fromPredictionModel.featuresCol()
, callingpredict
, and storing the predictions as a new columnPredictionModel.predictionCol()
.- Overrides:
transform
in classPredictionModel<Vector,
DecisionTreeRegressionModel> - Parameters:
dataset
- input dataset- Returns:
- transformed dataset with
PredictionModel.predictionCol()
of typeDouble
-
copy
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. SeedefaultCopy()
.- Specified by:
copy
in interfaceParams
- Specified by:
copy
in classModel<DecisionTreeRegressionModel>
- Parameters:
extra
- (undocumented)- Returns:
- (undocumented)
-
toString
Description copied from interface:DecisionTreeModel
Summary of the model- Specified by:
toString
in interfaceDecisionTreeModel
- Specified by:
toString
in interfaceIdentifiable
- Overrides:
toString
in classObject
-
featureImportances
-
write
Description copied from interface:MLWritable
Returns anMLWriter
instance for this ML instance.- Specified by:
write
in interfaceMLWritable
- Returns:
- (undocumented)
-