pycaret / pycaret

An open-source, low-code machine learning library in Python
https://www.pycaret.org
MIT License
8.93k stars 1.77k forks source link

[BUG]: No tree visualization for RF & DT: AttributeError: 'NoneType' object has no attribute 'classes_' #2992

Closed LerysG closed 1 year ago

LerysG commented 2 years ago

pycaret version checks

Issue Description

Impossible to visualize the decision tree (in evaluate model) using random forest or decision tree classifiers: AttributeError: 'NoneType' object has no attribute 'classes_'

Reproducible Example

from pycaret.classification import *

clf1 = setup(data=df1, target='target')
rf = create_model('rf', fold=4)
evaluate_model(rf)

Expected Behavior

Clicking on decision tree tab, should print image of the tree.

Actual Results

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
~\Anaconda3\lib\site-packages\ipywidgets\widgets\interaction.py in update(self, *args)
    255                     value = widget.get_interact_value()
    256                     self.kwargs[widget._kwarg] = value
--> 257                 self.result = self.f(**self.kwargs)
    258                 show_inline_matplotlib_plots()
    259                 if self.auto_display and self.result is not None:

~\AppData\Roaming\Python\Python39\site-packages\pycaret\internal\pycaret_experiment\tabular_experiment.py in _plot_model(self, estimator, plot, scale, save, fold, fit_kwargs, plot_kwargs, groups, feature_name, label, use_train_data, verbose, system, display, display_format)
   1958                 # execute the plot method
   1959                 with redirect_output(self.logger):
-> 1960                     ret = locals()[plot]()
   1961                 if ret:
   1962                     plot_filename = ret

~\AppData\Roaming\Python\Python39\site-packages\pycaret\internal\pycaret_experiment\tabular_experiment.py in tree()
   1524                             i: class_name
   1525                             for i, class_name in enumerate(
-> 1526                                 get_label_encoder(self.pipeline).classes_
   1527                             )
   1528                         }

AttributeError: 'NoneType' object has no attribute 'classes_'

Installed Versions

System: python: 3.9.12 (main, Apr 4 2022, 05:22:27) [MSC v.1916 64 bit (AMD64)] executable: C:\Users\XXX\Anaconda3\python.exe machine: Windows-10-10.0.19041-SP0 PyCaret required dependencies: pip: 21.2.4 setuptools: 60.10.0 pycaret: 3.0.0rc4 IPython: 8.2.0 ipywidgets: 7.6.5 tqdm: 4.64.0 numpy: 1.21.5 pandas: 1.4.2 jinja2: 2.11.3 scipy: 1.7.3 joblib: 1.1.0 sklearn: 1.1.2 pyod: 1.0.5 imblearn: 0.9.1 category_encoders: 2.5.0 lightgbm: 3.3.2 numba: 0.55.1 requests: 2.27.1 matplotlib: 3.5.1 scikitplot: 0.3.7 yellowbrick: 1.5 plotly: 5.6.0 kaleido: 0.2.1 statsmodels: 0.13.2 sktime: 0.13.2 tbats: 1.1.0 pmdarima: 1.8.5 psutil: 5.9.2 PyCaret optional dependencies: shap: Not installed interpret: Not installed umap: Not installed pandas_profiling: Not installed explainerdashboard: Not installed autoviz: 0.1.55 fairlearn: Not installed xgboost: 1.6.2 catboost: Not installed kmodes: Not installed mlxtend: Not installed statsforecast: Not installed tune_sklearn: Not installed ray: Not installed hyperopt: Not installed optuna: Not installed skopt: Not installed mlflow: Not installed gradio: Not installed fastapi: Not installed uvicorn: Not installed m2cgen: Not installed evidently: Not installed nltk: 3.7 pyLDAvis: Not installed gensim: 4.1.2 spacy: Not installed wordcloud: 1.8.2.2 textblob: 0.17.1 fugue: Not installed streamlit: Not installed prophet: Not installed
ArtificialZeng commented 2 years ago

same bug https://github.com/pycaret/pycaret/issues/2996

rcshetty3 commented 2 years ago

I have the same issue, please help

huaji1992 commented 2 years ago

I have the same issue, please help

moezali1 commented 1 year ago

@LerysG @ArtificialZeng @rcshetty3 The issue has been fixed in the latest rc version. Can you try installing pycaret in new env with pip install --pre pycaret and try again? It should work.

image