我有一个RandomForestRegressor
,GBTRegressor
,我想获取它们的所有参数。如何获取PySpark中估计器的所有参数
from pyspark.ml.regression import RandomForestRegressor, GBTRegressor
est = RandomForestRegressor()
est.getMaxDepth()
est.getSeed()
但RandomForestRegressor
和GBTRegressor
有不同的参数,所以它不是铁杆所有的方法是一个好主意:我发现的唯一方式,它可以与几个get方法等来完成。 一种解决方法可能是这样的:
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}
但我觉得应该有一个更好的方式来做到这一点。
我看到那个方法,但我错过了它与价值观字典...谢谢。 –