Skip to content

[SPARK-20498][PYSPARK][ML] Expose getMaxDepth for ensemble tree model in PySpark #18120

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions python/pyspark/ml/classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -862,6 +862,8 @@ class RandomForestClassifier(JavaEstimator, HasFeaturesCol, HasLabelCol, HasPred
>>> model_path = temp_path + "/rfc_model"
>>> model.save(model_path)
>>> model2 = RandomForestClassificationModel.load(model_path)
>>> model.getMaxDepth() == model2.getMaxDepth()
True
>>> model.featureImportances == model2.featureImportances
True

Expand Down Expand Up @@ -997,6 +999,8 @@ class GBTClassifier(JavaEstimator, HasFeaturesCol, HasLabelCol, HasPredictionCol
>>> model_path = temp_path + "gbtc_model"
>>> model.save(model_path)
>>> model2 = GBTClassificationModel.load(model_path)
>>> model.getMaxDepth() == model2.getMaxDepth()
True
>>> model.featureImportances == model2.featureImportances
True
>>> model.treeWeights == model2.treeWeights
Expand Down
10 changes: 10 additions & 0 deletions python/pyspark/ml/regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,12 @@ def getNumTrees(self):
"""Number of trees in ensemble."""
return self._call_java("getNumTrees")

@property
@since("2.3.0")
def getMaxDepth(self):
"""Maximum depth of the tree (>= 0)."""
return self._call_java("getMaxDepth")

@property
@since("1.5.0")
def treeWeights(self):
Expand Down Expand Up @@ -877,6 +883,8 @@ class RandomForestRegressor(JavaEstimator, HasFeaturesCol, HasLabelCol, HasPredi
>>> model_path = temp_path + "/rfr_model"
>>> model.save(model_path)
>>> model2 = RandomForestRegressionModel.load(model_path)
>>> model.getMaxDepth() == model2.getMaxDepth()
True
>>> model.featureImportances == model2.featureImportances
True

Expand Down Expand Up @@ -996,6 +1004,8 @@ class GBTRegressor(JavaEstimator, HasFeaturesCol, HasLabelCol, HasPredictionCol,
>>> model_path = temp_path + "gbtr_model"
>>> model.save(model_path)
>>> model2 = GBTRegressionModel.load(model_path)
>>> model.getMaxDepth() == model2.getMaxDepth()
True
>>> model.featureImportances == model2.featureImportances
True
>>> model.treeWeights == model2.treeWeights
Expand Down