Decision Tree
Setting Up Decision Tree Regression
Load in required libraries
from pyspark.ml.regression import DecisionTreeRegressor
from pyspark.ml.tuning import ParamGridBuilder, CrossValidator
from pyspark.ml.evaluation import RegressionEvaluatorInitialize Decision Tree object
dt = DecisionTreeRegressor(labelCol="label", featuresCol="features")Create a parameter grid for tuning the model
dtparamGrid = (ParamGridBuilder()
.addGrid(dt.maxDepth, [2, 5, 10, 20, 30])
#.addGrid(dt.maxDepth, [2, 5, 10])
.addGrid(dt.maxBins, [10, 20, 40, 80, 100])
#.addGrid(dt.maxBins, [10, 20])
.build())Define how you want the model to be evaluated
Define the type of cross-validation you want to perform
Fit the model to the data
Score the testing dataset using your fitted model for evaluation purposes
Evaluate the model
Last updated
Was this helpful?