DistrictDataLabs / yellowbrick

Visual analysis and diagnostic tools to facilitate machine learning model selection.
http://www.scikit-yb.org/
Apache License 2.0
4.3k stars 559 forks source link

'RandomForestClassifier' object has no attribute 'absolute' #1268

Closed leokaplun closed 2 years ago

leokaplun commented 2 years ago

Describe the bug I'm running the code from the Feature Importance example on the website.

Here is the code I used:

X = pd.DataFrame({'BILL_AMT3': {0: 689, 1: 2682, 2: 13559, 3: 49291, 4: 35835},
 'BILL_AMT5': {0: 0, 1: 3455, 2: 14948, 3: 28959, 4: 19146},
 'AGE': {0: 24, 1: 26, 2: 34, 3: 37, 4: 57},
 'LIMIT_BAL': {0: 20000, 1: 120000, 2: 90000, 3: 50000, 4: 50000},
 'PAY_AMT1': {0: 0, 1: 0, 2: 1518, 3: 2000, 4: 2000},
 'MARRIAGE': {0: 1, 1: 2, 2: 2, 3: 1, 4: 1}})
y = pd.Series({0: 1, 1: 1, 2: 0, 3: 0, 4: 0})

from sklearn.ensemble import RandomForestClassifier
from yellowbrick.model_selection import FeatureImportances
model = RandomForestClassifier(n_estimators=10)
viz = FeatureImportances(model,is_fitted=True)
viz.fit(X, y)
viz.show()

Traceback

I---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Input In [96], in <cell line: 13>()
     11 from yellowbrick.model_selection import FeatureImportances
     12 model = RandomForestClassifier(n_estimators=10)
---> 13 viz = FeatureImportances(model,is_fitted=True)
     14 viz.fit(X, y)
     15 viz.show()

File ~/opt/anaconda3/lib/python3.8/site-packages/yellowbrick/model_selection/importances.py:139, in FeatureImportances.__init__(self, model, ax, labels, relative, absolute, xlabel, stack, colors, colormap, is_fitted, **kwargs)
    134 super(FeatureImportances, self).__init__(
    135     model, ax=ax, is_fitted=is_fitted, **kwargs
    136 )
    138 # Data Parameters
--> 139 self.set_params(
    140     labels=labels,
    141     relative=relative,
    142     absolute=absolute,
    143     xlabel=xlabel,
    144     stack=stack,
    145     colors=colors,
    146     colormap=colormap,
    147 )

File ~/opt/anaconda3/lib/python3.8/site-packages/sklearn/base.py:239, in BaseEstimator.set_params(self, **params)
    236 if not params:
    237     # Simple optimization to gain speed (inspect is slow)
    238     return self
--> 239 valid_params = self.get_params(deep=True)
    241 nested_params = defaultdict(dict)  # grouped by prefix
    242 for key, value in params.items():

File ~/opt/anaconda3/lib/python3.8/site-packages/sklearn/base.py:211, in BaseEstimator.get_params(self, deep)
    209 out = dict()
    210 for key in self._get_param_names():
--> 211     value = getattr(self, key)
    212     if deep and hasattr(value, "get_params"):
    213         deep_items = value.get_params().items()

File ~/opt/anaconda3/lib/python3.8/site-packages/yellowbrick/utils/wrapper.py:42, in Wrapper.__getattr__(self, attr)
     40 def __getattr__(self, attr):
     41     # proxy to the wrapped object
---> 42     return getattr(self._wrapped, attr)

AttributeError: 'RandomForestClassifier' object has no attribute 'absolute'

Desktop (please complete the following information):

lwgray commented 2 years ago

@leokaplun Thank you for using Yellowbrick. Can you try to change is_fitted to False?

bbengfort commented 2 years ago

@leokaplun we just released Yellowbrick v1.5 which fixes an AttributeError bug that is likely related to the one you're experiencing, please update Yellowbrick to the latest version for the fix!