<p>不幸的是,在使用低级xgb api时,获取增压器参数并非易事</p>
<p>以下是我如何找到我所寻找的助推器参数:</p>
<pre class="lang-py prettyprint-override"><code># this retrieves all booster and non-booster parameters
import json
config = json.loads(lowlevel_xgb.save_config()) # your xgb booster object
stack = [config]
internal = {}
while stack:
obj = stack.pop()
for k, v in obj.items():
if k.endswith('_param'):
for p_k, p_v in v.items():
internal[p_k] = p_v
elif isinstance(v, dict):
stack.append(v)
# retrieve all parameter values from xgb.train in param search dict
from nested_lookup import nested_lookup
lowlevelconfig = {}
for key in search_params_dict: #dict of parameters you want to search for
lowlevelconfig[key] = nested_lookup(key,config)
</code></pre>
<p>在我的例子中,我想比较默认的低级api参数(即使用<code>xgb.train</code>)和使用scikit包装器的默认参数(即使用<code>XGBClassifier</code>)。不幸的是,它们不一样</p>
<p>如果你有同样的情况,你可以像我一样:</p>
<pre class="lang-py prettyprint-override"><code>from nested_lookup import nested_lookup
lowlevelconfig = {}
for key in sci_xgb.get_params():#where sci_xgb is your scikit xgb model
lowlevelconfig[key] = nested_lookup(key,config)
</code></pre>
<p>这样,您就可以比较低级xgb api和scikit包装器的增压器参数</p>