0

我正在尝试使用 k 折交叉验证来调整 pyspark 中生成的回归树。但是,从我目前所见,将 pyspark 的 CrossValidator 与 pyspark 的 DecisionTree.trainRegressor 结合起来是不可能的。这是相关的代码。

    (trainingData, testData) = data.randomSplit([0.7, 0.3])

    model = DecisionTree.trainRegressor(trainingData, categoricalFeaturesInfo={}, impurity='variance', maxDepth=5, maxBins=32)

然后如何将 k 折交叉验证应用于回归器?

4

1 回答 1

1

你可以试试这个:

(trainingData, testData) = data.randomSplit([0.7, 0.3])

model = DecisionTree.trainRegressor(trainingData, categoricalFeaturesInfo={}, impurity='variance', numClasses=2)

paramGrid = ParamGridBuilder() \
    .addGrid(model.maxDepth, [4, 5, 6, 7]) \
    .addGrid(model.maxBins, [24, 28, 32, 36]) \
    .build()

crossval = CrossValidator(estimator=model,
                          estimatorParamMaps=paramGrid,
                          evaluator=BinaryClassificationEvaluator(),
                          numFolds=3)  

# Run cross-validation, and choose the best set of parameters.
cvModel = crossval.fit(training)
于 2019-10-04T04:48:41.013 回答