yellowbrick 实现错误 - AttributeError:“LogisticRegression”对象没有属性“fig”

问题描述 投票:0回答:1

我是 Yellowbrick 的新用户。在 Yellowbrick ClassificationReport 中实现 sklearn LogisticRegression API 时,我发现了一些不寻常的错误。我已经尝试了 Yellowbrick 官方文档以及大多数数据科学社区用户(中等等)建议的许多语法,但我仍然遇到相同的错误。虽然我收到了 ClassificationReport,但错误很烦人。

#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
python scikit-learn classification yellowbrick
1个回答
1
投票

sklearn版本0.22.2.post1yellowbrick版本0.9.1为我解决了这个问题。通过运行安装这些:

pip install scikit-learn==0.22.2.post1

pip install yellowbrick==0.9.1

© www.soinside.com 2019 - 2024. All rights reserved.