I've got the following code. I'll include only the problematic bits:
class C:
def __init__(self,**kwargs):
self.kwargs = kwargs
def fit(...):
...
c = self.learner(**self.kwargs)
I'm attempting to use this with the following class:
class learner:
def __init__(self, X):
self.X = X
kwargs={'X': X}
inst = C(kwargs=kwargs)
inst.fit(...)
Which is yielding the error, at the line inst.fit(...). The error is: learner.__init__() got an unexpected keyword argument 'kwargs'. How do I fix my instantiation? It seems as though the dictionary is not being unpacked, despite employing **. Help would be very appreciated.
By destructuring your
kwargsin the constructor ofBoostwhat you are actually storing inself.kwargsis a dictionary that looks like this:Passing this to the
wk_learnerconstructor using**self.kwargsmeans python tries to look for a keyword argument calledkwargswhich doesn't exist, hence the error message.You can fix the problem by not destructuring in the
Boostconstructor (and maybe also renaming the parameter to avoid confusion):