scikit-learn-contrib / DESlib

A Python library for dynamic classifier and ensemble selection
BSD 3-Clause "New" or "Revised" License
479 stars 106 forks source link

'RandomForestClassifier' object has no attribute 'estimators_' #220

Closed jayahm closed 3 years ago

jayahm commented 4 years ago

Hi,

I followed your example on RF and DS https://deslib.readthedocs.io/en/latest/auto_examples/plot_random_forest.html

However, I got this error on stacked classfier.

~\anaconda3\lib\site-packages\deslib\static\stacked.py in fit(self, X, y)
     69         X, y = check_X_y(X, y)
     70 
---> 71         super(StackedClassifier, self).fit(X, y)
     72         base_preds = self._predict_proba_base(X)
     73         X_meta = self._connect_input(X, base_preds)

~\anaconda3\lib\site-packages\deslib\static\base.py in fit(self, X, y)
     80             self.pool_classifiers_ = self.pool_classifiers
     81 
---> 82         self.n_classifiers_ = len(self.pool_classifiers_)
     83 
     84         # dealing with label encoder

~\anaconda3\lib\site-packages\sklearn\ensemble\_base.py in __len__(self)
    159     def __len__(self):
    160         """Return the number of estimators in the ensemble."""
--> 161         return len(self.estimators_)
    162 
    163     def __getitem__(self, index):

AttributeError: 'RandomForestClassifier' object has no attribute 'estimators_'
Menelau commented 3 years ago

Hello,

Can you give me the versions of each library you are using (Scikit-learn and DESlib)? I have no problems in running this example in my environment, so it could be some problems with different versions.

jayahm commented 3 years ago

What I meant was I followed the code and run on my dataset, including stacked classifier as well.

The deslib version is 0.4.dev. The scikit-learn version is 0.22.1.

Menelau commented 3 years ago

Hello,

I just run this same example with scikit-learn=0.22.1 and deslib=0.4dev and had no problems with it. Moreover, our CI also test the examples and found no problems with it.

I'm guessing the problem is on the code part you changed. So without having access to your code I cannot do anything.