如何更改 sklearn.metrics 包中的 plot_confusion_matrix 默认图形大小

Rom*_*ker 8 matplotlib python-3.x confusion-matrix scikit-learn jupyter-notebook

我尝试使用 sklearn.metrics.plot_confusion_matrix 包用 Jupyter notebook 绘制混淆矩阵,但默认图形大小有点小。我在绘图之前添加了 plt.figure(figsize=(20, 20)) ,但图形大小没有随输出文本“图形大小 1440x1440 与 0 轴”而变化。如何更改图形大小?

%matplotlib inline
from sklearn.ensemble import GradientBoostingClassifier
from sklearn.metrics import plot_confusion_matrix
from matplotlib import pyplot as plt

plt.figure(figsize=(20, 20))
clf = GradientBoostingClassifier(random_state=42)
clf.fit(X_train, y_train)
plot_confusion_matrix(clf, X_test, y_test, cmap=plt.cm.Blues)
plt.title('Confusion matrix')
plt.show()
Run Code Online (Sandbox Code Playgroud)

就像这张图片

小智 11

我不知道为什么 BigBen 将其作为评论而不是答案发布,但我差点没看到它。这里是一个答案,所以未来的旁观者不要犯我几乎犯过的错误!

fig, ax = plt.subplots(figsize=(10, 10))
plot_confusion_matrix(your_model, X_test, y_test, ax=ax)
Run Code Online (Sandbox Code Playgroud)