【发布时间】:2017-07-21 19:28:48
【问题描述】:
我有一个RandomForestRegressor、GBTRegressor,我想获取它们的所有参数。我发现它的唯一方法可以通过几个 get 方法来完成,例如:
from pyspark.ml.regression import RandomForestRegressor, GBTRegressor
est = RandomForestRegressor()
est.getMaxDepth()
est.getSeed()
但是RandomForestRegressor 和GBTRegressor 有不同的参数,所以硬核所有这些方法并不是一个好主意。
解决方法可能是这样的:
get_methods = [method for method in dir(est) if method.startswith('get')]
params_est = {}
for method in get_methods:
try:
key = method[3:]
params_est[key] = getattr(est, method)()
except TypeError:
pass
那么输出会是这样的:
params_est
{'CacheNodeIds': False,
'CheckpointInterval': 10,
'FeatureSubsetStrategy': 'auto',
'FeaturesCol': 'features',
'Impurity': 'variance',
'LabelCol': 'label',
'MaxBins': 32,
'MaxDepth': 5,
'MaxMemoryInMB': 256,
'MinInfoGain': 0.0,
'MinInstancesPerNode': 1,
'NumTrees': 20,
'PredictionCol': 'prediction',
'Seed': None,
'SubsamplingRate': 1.0}
但我认为应该有更好的方法来做到这一点。
【问题讨论】:
标签: apache-spark pyspark apache-spark-ml