yellowbrick implementation error - AttributeError: 'LogisticRegression' object has no attribute 'fig'

1k views Asked by At

I am a new user for yellowbrick. While implementing a sklearn LogisticRegression API in yellowbrick ClassificationReport, I found some unusual error. I have tried many syntaxes as suggested by yellowbrick official document as well as in most data science community user (medium etc.), but still I am getting the same error. Though I am getting the ClassificationReport but the error is quite annoying.

#Using yellowbrick library
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import train_test_split

from sklearn.metrics import confusion_matrix, roc_auc_score, recall_score, roc_curve, accuracy_score, auc, classification_report, plot_confusion_matrix, plot_roc_curve, precision_score, f1_score
from yellowbrick.classifier import ClassificationReport, discrimination_threshold, classification_report

classes = [0,1]

fig = plt.gcf()
ax = plt.subplot(111)
visualizer = ClassificationReport(log_model,classes=[0,1], size=(400,400),fontsize=15, cmap='GnBu', ax = ax)
ax.grid(False)
plt.title("Classification Report", fontsize=18)

visualizer.fit(X_train, y_train)
visualizer.score(X_test, y_test)
visualizer.poof()
#visualizer.show() #I even tried this (This also gives me an error like LogisticRegression object has no attribute 'show'

The output I am getting is:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-89-f01efe3e9a6d> in <module>()
     16 visualizer.fit(X_train, y_train)
     17 visualizer.score(X_test, y_test)
---> 18 visualizer.poof()

2 frames
/usr/local/lib/python3.7/dist-packages/yellowbrick/utils/wrapper.py in __getattr__(self, attr)
     40     def __getattr__(self, attr):
     41         # proxy to the wrapped object
---> 42         return getattr(self._wrapped, attr)

AttributeError: 'LogisticRegression' object has no attribute 'fig'

Appreciate any suggestion to get rid of this error.

To add, currently I am using following scikit-learn and yellowbrick versions:

print(sklearn.__version__)
print(yellowbrick.__version__)

0.24.2
0.9.1
1

There are 1 answers

0
Rafsun Jany Arman On

sklearn version 0.22.2.post1 and yellowbrick version 0.9.1 fix the issue for me. Install these by running:

pip install scikit-learn==0.22.2.post1

and

pip install yellowbrick==0.9.1