GBTRegressionModel¶
-
class
pyspark.ml.regression.
GBTRegressionModel
(java_model: Optional[JavaObject] = None)¶ Model fitted by
GBTRegressor
.Methods
clear
(param)Clears a param from the param map if it has been explicitly set.
copy
([extra])Creates a copy of this instance with the same uid and some extra params.
evaluateEachIteration
(dataset, loss)Method to compute error or loss for every iteration of gradient boosting.
explainParam
(param)Explains a single param and returns its name, doc, and optional default value and user-supplied value in a string.
Returns the documentation of all params with their optionally default values and user-supplied values.
extractParamMap
([extra])Extracts the embedded default param values and user-supplied values, and then merges them with extra values from input into a flat param map, where the latter value is used if there exist conflicts, i.e., with ordering: default param values < user-supplied values < extra.
Gets the value of cacheNodeIds or its default value.
Gets the value of checkpointInterval or its default value.
Gets the value of featureSubsetStrategy or its default value.
Gets the value of featuresCol or its default value.
Gets the value of impurity or its default value.
Gets the value of labelCol or its default value.
Gets the value of leafCol or its default value.
Gets the value of lossType or its default value.
Gets the value of maxBins or its default value.
Gets the value of maxDepth or its default value.
Gets the value of maxIter or its default value.
Gets the value of maxMemoryInMB or its default value.
Gets the value of minInfoGain or its default value.
Gets the value of minInstancesPerNode or its default value.
Gets the value of minWeightFractionPerNode or its default value.
getOrDefault
(param)Gets the value of a param in the user-supplied param map or its default value.
getParam
(paramName)Gets a param by its name.
Gets the value of predictionCol or its default value.
getSeed
()Gets the value of seed or its default value.
Gets the value of stepSize or its default value.
Gets the value of subsamplingRate or its default value.
Gets the value of validationIndicatorCol or its default value.
Gets the value of validationTol or its default value.
Gets the value of weightCol or its default value.
hasDefault
(param)Checks whether a param has a default value.
hasParam
(paramName)Tests whether this instance contains a param with a given (string) name.
isDefined
(param)Checks whether a param is explicitly set by user or has a default value.
isSet
(param)Checks whether a param is explicitly set by user.
load
(path)Reads an ML instance from the input path, a shortcut of read().load(path).
predict
(value)Predict label for the given features.
predictLeaf
(value)Predict the indices of the leaves corresponding to the feature vector.
read
()Returns an MLReader instance for this class.
save
(path)Save this ML instance to the given path, a shortcut of ‘write().save(path)’.
set
(param, value)Sets a parameter in the embedded param map.
setFeaturesCol
(value)Sets the value of
featuresCol
.setLeafCol
(value)Sets the value of
leafCol
.setPredictionCol
(value)Sets the value of
predictionCol
.transform
(dataset[, params])Transforms the input dataset with optional parameters.
write
()Returns an MLWriter instance for this ML instance.
Attributes
Estimate of the importance of each feature.
Number of trees in ensemble.
Returns the number of features the model was trained on.
Returns all params ordered by name.
Full description of model.
Total number of nodes, summed over all trees in the ensemble.
Return the weights for each tree
Trees in this ensemble.
Methods Documentation
-
clear
(param: pyspark.ml.param.Param) → None¶ Clears a param from the param map if it has been explicitly set.
-
copy
(extra: Optional[ParamMap] = None) → JP¶ Creates a copy of this instance with the same uid and some extra params. This implementation first calls Params.copy and then make a copy of the companion Java pipeline component with extra params. So both the Python wrapper and the Java pipeline component get copied.
- Parameters
- extradict, optional
Extra parameters to copy to the new instance
- Returns
JavaParams
Copy of this instance
-
evaluateEachIteration
(dataset: pyspark.sql.dataframe.DataFrame, loss: str) → List[float]¶ Method to compute error or loss for every iteration of gradient boosting.
- Parameters
- dataset
pyspark.sql.DataFrame
Test dataset to evaluate model on, where dataset is an instance of
pyspark.sql.DataFrame
- lossstr
The loss function used to compute error. Supported options: squared, absolute
- dataset
-
explainParam
(param: Union[str, pyspark.ml.param.Param]) → str¶ Explains a single param and returns its name, doc, and optional default value and user-supplied value in a string.
-
explainParams
() → str¶ Returns the documentation of all params with their optionally default values and user-supplied values.
-
extractParamMap
(extra: Optional[ParamMap] = None) → ParamMap¶ Extracts the embedded default param values and user-supplied values, and then merges them with extra values from input into a flat param map, where the latter value is used if there exist conflicts, i.e., with ordering: default param values < user-supplied values < extra.
- Parameters
- extradict, optional
extra param values
- Returns
- dict
merged param map
-
getCacheNodeIds
() → bool¶ Gets the value of cacheNodeIds or its default value.
-
getCheckpointInterval
() → int¶ Gets the value of checkpointInterval or its default value.
-
getFeatureSubsetStrategy
() → str¶ Gets the value of featureSubsetStrategy or its default value.
-
getFeaturesCol
() → str¶ Gets the value of featuresCol or its default value.
-
getImpurity
() → str¶ Gets the value of impurity or its default value.
-
getLabelCol
() → str¶ Gets the value of labelCol or its default value.
-
getLeafCol
() → str¶ Gets the value of leafCol or its default value.
-
getLossType
() → str¶ Gets the value of lossType or its default value.
-
getMaxBins
() → int¶ Gets the value of maxBins or its default value.
-
getMaxDepth
() → int¶ Gets the value of maxDepth or its default value.
-
getMaxIter
() → int¶ Gets the value of maxIter or its default value.
-
getMaxMemoryInMB
() → int¶ Gets the value of maxMemoryInMB or its default value.
-
getMinInfoGain
() → float¶ Gets the value of minInfoGain or its default value.
-
getMinInstancesPerNode
() → int¶ Gets the value of minInstancesPerNode or its default value.
-
getMinWeightFractionPerNode
() → float¶ Gets the value of minWeightFractionPerNode or its default value.
-
getOrDefault
(param: Union[str, pyspark.ml.param.Param[T]]) → Union[Any, T]¶ Gets the value of a param in the user-supplied param map or its default value. Raises an error if neither is set.
-
getParam
(paramName: str) → pyspark.ml.param.Param¶ Gets a param by its name.
-
getPredictionCol
() → str¶ Gets the value of predictionCol or its default value.
-
getSeed
() → int¶ Gets the value of seed or its default value.
-
getStepSize
() → float¶ Gets the value of stepSize or its default value.
-
getSubsamplingRate
() → float¶ Gets the value of subsamplingRate or its default value.
-
getValidationIndicatorCol
() → str¶ Gets the value of validationIndicatorCol or its default value.
-
getValidationTol
() → float¶ Gets the value of validationTol or its default value.
-
getWeightCol
() → str¶ Gets the value of weightCol or its default value.
-
hasDefault
(param: Union[str, pyspark.ml.param.Param[Any]]) → bool¶ Checks whether a param has a default value.
-
hasParam
(paramName: str) → bool¶ Tests whether this instance contains a param with a given (string) name.
-
isDefined
(param: Union[str, pyspark.ml.param.Param[Any]]) → bool¶ Checks whether a param is explicitly set by user or has a default value.
-
isSet
(param: Union[str, pyspark.ml.param.Param[Any]]) → bool¶ Checks whether a param is explicitly set by user.
-
classmethod
load
(path: str) → RL¶ Reads an ML instance from the input path, a shortcut of read().load(path).
-
predict
(value: T) → float¶ Predict label for the given features.
-
predictLeaf
(value: pyspark.ml.linalg.Vector) → float¶ Predict the indices of the leaves corresponding to the feature vector.
-
classmethod
read
() → pyspark.ml.util.JavaMLReader[RL]¶ Returns an MLReader instance for this class.
-
save
(path: str) → None¶ Save this ML instance to the given path, a shortcut of ‘write().save(path)’.
-
set
(param: pyspark.ml.param.Param, value: Any) → None¶ Sets a parameter in the embedded param map.
-
setFeaturesCol
(value: str) → P¶ Sets the value of
featuresCol
.
-
setPredictionCol
(value: str) → P¶ Sets the value of
predictionCol
.
-
transform
(dataset: pyspark.sql.dataframe.DataFrame, params: Optional[ParamMap] = None) → pyspark.sql.dataframe.DataFrame¶ Transforms the input dataset with optional parameters.
- Parameters
- dataset
pyspark.sql.DataFrame
input dataset
- paramsdict, optional
an optional param map that overrides embedded params.
- dataset
- Returns
pyspark.sql.DataFrame
transformed dataset
-
write
() → pyspark.ml.util.JavaMLWriter¶ Returns an MLWriter instance for this ML instance.
Attributes Documentation
-
cacheNodeIds
= Param(parent='undefined', name='cacheNodeIds', doc='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.')¶
-
checkpointInterval
= Param(parent='undefined', name='checkpointInterval', doc='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.')¶
-
featureImportances
¶ Estimate of the importance of each feature.
Each feature’s importance is the average of its importance across all trees in the ensemble The importance vector is normalized to sum to 1. This method is suggested by Hastie et al. (Hastie, Tibshirani, Friedman. “The Elements of Statistical Learning, 2nd Edition.” 2001.) and follows the implementation from scikit-learn.
Examples
DecisionTreeRegressionModel.featureImportances
-
featureSubsetStrategy
= Param(parent='undefined', name='featureSubsetStrategy', doc="The number of features to consider for splits at each tree node. Supported options: 'auto' (choose automatically for task: If numTrees == 1, set to 'all'. If numTrees > 1 (forest), set to 'sqrt' for classification and to 'onethird' for regression), 'all' (use all features), 'onethird' (use 1/3 of the features), 'sqrt' (use sqrt(number of features)), 'log2' (use log2(number of features)), 'n' (when n is in the range (0, 1.0], use n * number of features. When n is in the range (1, number of features), use n features). default = 'auto'")¶
-
featuresCol
= Param(parent='undefined', name='featuresCol', doc='features column name.')¶
-
getNumTrees
¶ Number of trees in ensemble.
-
impurity
= Param(parent='undefined', name='impurity', doc='Criterion used for information gain calculation (case-insensitive). Supported options: variance')¶
-
labelCol
: Param[str] = Param(parent='undefined', name='labelCol', doc='label column name.')¶
-
leafCol
= Param(parent='undefined', name='leafCol', doc='Leaf indices column name. Predicted leaf index of each instance in each tree by preorder.')¶
-
lossType
= Param(parent='undefined', name='lossType', doc='Loss function which GBT tries to minimize (case-insensitive). Supported options: squared, absolute')¶
-
maxBins
= Param(parent='undefined', name='maxBins', doc='Max number of bins for discretizing continuous features. Must be >=2 and >= number of categories for any categorical feature.')¶
-
maxDepth
= Param(parent='undefined', name='maxDepth', doc='Maximum depth of the tree. (>= 0) E.g., depth 0 means 1 leaf node; depth 1 means 1 internal node + 2 leaf nodes. Must be in range [0, 30].')¶
-
maxIter
= Param(parent='undefined', name='maxIter', doc='max number of iterations (>= 0).')¶
-
maxMemoryInMB
= Param(parent='undefined', name='maxMemoryInMB', doc='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.')¶
-
minInfoGain
= Param(parent='undefined', name='minInfoGain', doc='Minimum information gain for a split to be considered at a tree node.')¶
-
minInstancesPerNode
= Param(parent='undefined', name='minInstancesPerNode', doc='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. Should be >= 1.')¶
-
minWeightFractionPerNode
= Param(parent='undefined', name='minWeightFractionPerNode', doc='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 interval [0.0, 0.5).')¶
-
numFeatures
¶ Returns the number of features the model was trained on. If unknown, returns -1
-
params
¶ Returns all params ordered by name. The default implementation uses
dir()
to get all attributes of typeParam
.
-
predictionCol
= Param(parent='undefined', name='predictionCol', doc='prediction column name.')¶
-
seed
= Param(parent='undefined', name='seed', doc='random seed.')¶
-
stepSize
= Param(parent='undefined', name='stepSize', doc='Step size (a.k.a. learning rate) in interval (0, 1] for shrinking the contribution of each estimator.')¶
-
subsamplingRate
= Param(parent='undefined', name='subsamplingRate', doc='Fraction of the training data used for learning each decision tree, in range (0, 1].')¶
-
supportedFeatureSubsetStrategies
= ['auto', 'all', 'onethird', 'sqrt', 'log2']¶
-
supportedImpurities
= ['variance']¶
-
supportedLossTypes
= ['squared', 'absolute']¶
-
toDebugString
¶ Full description of model.
-
totalNumNodes
¶ Total number of nodes, summed over all trees in the ensemble.
-
treeWeights
¶ Return the weights for each tree
-
trees
¶ Trees in this ensemble. Warning: These have null parent Estimators.
-
validationIndicatorCol
= Param(parent='undefined', name='validationIndicatorCol', doc='name of the column that indicates whether each row is for training or for validation. False indicates training; true indicates validation.')¶
-
validationTol
= Param(parent='undefined', name='validationTol', doc='Threshold for stopping early when fit with validation is used. If the error rate on the validation input changes by less than the validationTol, then learning will stop early (before `maxIter`). This parameter is ignored when fit without validation is used.')¶
-
weightCol
= Param(parent='undefined', name='weightCol', doc='weight column name. If this is not set or empty, we treat all instance weights as 1.0.')¶
-