如何从mglearn保存情节?我尝试了这段代码,但是它不起作用。
import numpy as np
import matplotlib.pyplot as plt
import mglearn
from fpdf import FPDF
f = mglearn.plots.plot_knn_classification(n_neighbors=3)
f.savefig("n_neighbors.pdf", bbox_inches='tight')
错误是AttributeError:“ NoneType”对象没有属性“ savefig”。 谢谢
答案 0 :(得分:0)
由于mglearn软件包使用matplotlib.pyplot
的绘图机制,因此您可以使用其保存机制,
mglearn.plots.plot_knn_classification(n_neighbors=3)
plt.savefig("n_neighbors.pdf", bbox_inches='tight')
答案 1 :(得分:0)
from sklearn.neighbors import KNeighborsClassifier
import matplotlib.pyplot as plt
import mglearn.plots
import numpy as np
import mglearn
from fpdf import FPDF
X, y = mglearn.datasets.make_forge()
mglearn.plots.plot_knn_classification(n_neighbors=3)
plt.savefig("n_neighbors.pdf", bbox_inches='tight')
此代码有效。