【发布时间】:2019-06-09 22:59:54
【问题描述】:
我想在 Apache Spark 中对我的随机森林模型执行网格搜索。但我找不到这样做的例子。有没有关于样本数据的示例,我可以使用 Grid Search 进行超参数调整?
【问题讨论】:
标签: apache-spark apache-spark-mllib
我想在 Apache Spark 中对我的随机森林模型执行网格搜索。但我找不到这样做的例子。有没有关于样本数据的示例,我可以使用 Grid Search 进行超参数调整?
【问题讨论】:
标签: apache-spark apache-spark-mllib
from pyspark.ml import Pipeline
from pyspark.ml.classification import RandomForestClassifier
from pyspark.ml.evaluation import BinaryClassificationEvaluator
from pyspark.ml.tuning import CrossValidator, ParamGridBuilder
rf = RandomForestClassifier(labelCol="indexedLabel", featuresCol="indexedFeatures", numTrees=10)
pipeline = Pipeline(stages=[rf])
paramGrid = ParamGridBuilder().addGrid(rf.numTrees, [10, 30]).build()
crossval = CrossValidator(estimator=pipeline,
estimatorParamMaps=paramGrid,
evaluator=BinaryClassificationEvaluator(),
numFolds=2)
cvModel = crossval.fit(training_df)
超参数和网格在 addGrid 方法中定义
【讨论】: