问题描述
我是 Yellowbrick 的新用户。在yellowbrick ClassificationReport 中实现sklearn LogisticRegression API 时,我发现了一些异常错误。我已经尝试了 Yellowbrick 官方文档以及大多数数据科学社区用户(中等等)建议的许多语法,但我仍然遇到相同的错误。虽然我得到了分类报告,但错误很烦人。
#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'
我得到的输出是:
---------------------------------------------------------------------------
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'
感谢任何消除此错误的建议。
补充一下,目前我正在使用以下 scikit-learn 和 Yellowbrick 版本:
print(sklearn.__version__)
print(yellowbrick.__version__)
0.24.2
0.9.1
解决方法
sklearn 版本 0.22.2.post1 和 yellowbrick 版本 0.9.1 为我解决了这个问题。通过运行安装这些:
pip install scikit-learn==0.22.2.post1
和
pip install yellowbrick==0.9.1