I have a class that holds a scikitlearn-RandomForestClassifier as a member variable.
In the __init__-method, it is first initialised to None,
def __init__(self):
self.classifier = None
and
later, once all necessary parameters are available, a RandomForestClassifier is created and
assigned to this member variable:
def init_classifier(self):
self.classifier = RandomForestClassifier(**params)
(In the debugger I can see that self.classifier has been initialised to something meaningful.)
In the class method that is supposed to fit the classifier to the data, it is first checked whether
the classifier has been initialised already:
if not self.classifier:
self.init_classifier()
This results in an AttributeError: 'RandomForestClassifier' object has no attribute 'estimators_'.
If the check is done by comparing to None explicitly,
if self.classifier is None:
self.init_classifier()
it runs through. Can someone explain to me where this AttributeError comes from?