【问题标题】:How to perform grid search for Random Forest using Apache Spark ML library如何使用 Apache Spark ML 库对随机森林执行网格搜索
【发布时间】:2019-06-09 22:59:54
【问题描述】:

我想在 Apache Spark 中对我的随机森林模型执行网格搜索。但我找不到这样做的例子。有没有关于样本数据的示例,我可以使用 Grid Search 进行超参数调整?

【问题讨论】:

标签: apache-spark apache-spark-mllib


【解决方案1】:
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 方法中定义

【讨论】:

    猜你喜欢
    • 2022-01-04
    • 2017-12-29
    • 2016-03-25
    • 2016-06-09
    • 2019-05-06
    • 2015-09-23
    • 2017-06-13
    • 2023-04-01
    • 2015-10-23
    相关资源
    最近更新 更多