我用 pySpark 训练随机森林。我想要一个包含网格中每个点的结果的 csv。
我的代码是:
estimator = RandomForestRegressor()
evaluator = RegressionEvaluator()
paramGrid = ParamGridBuilder().addGrid(estimator.numTrees, [2,3])\
.addGrid(estimator.maxDepth, [2,3])\
.addGrid(estimator.impurity, ['variance'])\
.addGrid(estimator.featureSubsetStrategy, ['sqrt'])\
.build()
pipeline = Pipeline(stages=[estimator])
crossval = CrossValidator(estimator=pipeline,
estimatorParamMaps=paramGrid,
evaluator=evaluator,
numFolds=3)
cvModel = crossval.fit(result)
所以我想要一个 csv:
numTrees | maxDepth | impurityMeasure
2 2 0.001
2 3 0.00023
Etc
做这个的最好方式是什么?
您必须组合不同的数据位:
-
Estimator
ParamMaps
提取使用getEstimatorParamMaps
method.
- 可以使用以下方式检索训练指标
avgMetrics
范围。
首先获取映射中声明的所有参数的名称和值:
params = [{p.name: v for p, v in m.items()} for m in cvModel.getEstimatorParamMaps()]
Thane zip
带有指标并转换为数据框
import pandas as pd
pd.DataFrame.from_dict([
{cvModel.getEvaluator().getMetricName(): metric, **ps}
for ps, metric in zip(params, cvModel.avgMetrics)
])
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)