This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pyspark.ml.tuning import ParamGridBuilder | |
import numpy as np | |
paramGrid = ParamGridBuilder() \ | |
.addGrid(rf.numTrees, [int(x) for x in np.linspace(start = 10, stop = 50, num = 3)]) \ | |
.addGrid(rf.maxDepth, [int(x) for x in np.linspace(start = 5, stop = 25, num = 3)]) \ | |
.build() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pyspark.ml.tuning import CrossValidator | |
from pyspark.ml.evaluation import RegressionEvaluator | |
crossval = CrossValidator(estimator=pipeline, | |
estimatorParamMaps=paramGrid, | |
evaluator=RegressionEvaluator(), | |
numFolds=3) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
print('numTrees - ', bestModel.getNumTrees) | |
print('maxDepth - ', bestModel.getOrDefault('maxDepth')) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pyspark.ml.regression import RandomForestRegressor | |
rf = RandomForestRegressor(labelCol="label", featuresCol="features") |
NewerOlder