我在用PySpark 2.0进行一个Kaggle竞赛。我想知道一个模型(RandomForest
)的行为取决于不同的参数。ParamGridBuilder()
允许为单个参数指定不同的值,然后执行(我猜)整个参数集的笛卡尔积。假设我的DataFrame
已经定义:
rdc = RandomForestClassifier()
pipeline = Pipeline(stages=STAGES + [rdc])
paramGrid = ParamGridBuilder().addGrid(rdc.maxDepth, [3, 10, 20])
.addGrid(rdc.minInfoGain, [0.01, 0.001])
.addGrid(rdc.numTrees, [5, 10, 20, 30])
.build()
evaluator = MulticlassClassificationEvaluator()
valid = TrainValidationSplit(estimator=pipeline,
estimatorParamMaps=paramGrid,
evaluator=evaluator,
trainRatio=0.50)
model = valid.fit(df)
result = model.bestModel.transform(df)
好的,现在我可以用手工函数检索简单的信息:
def evaluate(result):
predictionAndLabels = result.select("prediction", "label")
metrics = ["f1","weightedPrecision","weightedRecall","accuracy"]
for m in metrics:
evaluator = MulticlassClassificationEvaluator(metricName=m)
print(str(m) + ": " + str(evaluator.evaluate(predictionAndLabels)))
现在我想要几样东西:
print(model.validationMetrics)
显示了(看起来)包含每个模型准确性的列表,但我不知道引用哪个模型。如果我能检索到所有这些信息,我应该能够显示图表、条形图,并像处理Panda和sklearn
那样工作。
目前没有回答
相关问题 更多 >
编程相关推荐