h2o set_params() 正好接受 1 个参数(给定 2 个),即使只给定 1 个?

h2o set_params() takes exactly 1 argument (2 given), even though only 1 given?

获取错误

TypeError: set_params() takes exactly 1 argument (2 given)

尽管我似乎只提供了一个论点...

HYPARAMS = {
            unicode(HYPER_PARAM): best_random_forest.params[unicode(HYPER_PARAM)][u'actual']
            for HYPER_PARAM in list_of_hyperparams_names
            }
assert isinstance(HYPARAMS, dict)
print 'Setting optimal params for full-train model...'
pp.pprint(HYPARAMS)
model = model.set_params(HYPARAMS)

#output
{   u'col_sample_rate_per_tree': 1.0,
    u'max_depth': 3,
    u'min_rows': 1024.0,
    u'min_split_improvement': 0.001,
    u'mtries': 5,
    u'nbins': 3,
    u'nbins_cats': 8,
    u'ntrees': 8,
    u'sample_rate': 0.25}
model = model.set_params(OPTIM_HYPARAMS)
TypeError: set_params() takes exactly 1 argument (2 given)

正在查看 source code

def set_params(self, **parms):
    """Used by sklearn for updating parameters during grid search.

    Parameters
    ----------
      parms : dict
        A dictionary of parameters that will be set on this model.

    Returns
    -------
      Returns self, the current estimator object with the parameters all set as desired.
    """
    self._parms.update(parms)
    return self

似乎没有太多我认为可能出错的地方。任何人都知道我在这里遗漏了什么或导致此错误的原因是什么?

TLDR:需要将 keys/values 解压为 **kwargs 关键字以获得更新 _parms 字典的预期行为。

也一样
model = model.set_params(**HYPARAMS)  #see 

示例:

# here's a basic standin for the set_params method
>>> def kfunc(**parms):
...     print parms
... 

# what I was doing
>>> kfunc({1:2})
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: kfunc() takes exactly 0 arguments (1 given)
# and also tried
>>> kfunc(parms={1:2})
{'parms': {1: 2}}
>>> kfunc({u'1':2, u'2':3})
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: kfunc() takes exactly 0 arguments (1 given)

# what should have been done
>>> kfunc(**{'1':2})
{'1': 2}
>>> kfunc(**{u'1':2, u'2':3})
{u'1': 2, u'2': 3}

现在可以看出这与 h2o 没有直接关系,但无论如何都要保持 post 以便其他遇到此问题的人可能会发现,因为只是阅读方法(而且因为另一个 SE post 在示例中评论说我曾经实际使用变量作为 **kwarg 关键字甚至不在 Google 搜索 "How to use python variable as keyword for kwargs parameter?" 的第一页所以想为其添加更多途径)。