Python 我能';t绘制Matplotlib预测,我不断得到内存错误

Python 我能';t绘制Matplotlib预测,我不断得到内存错误,python,matplotlib,Python,Matplotlib,我正试图按照Krill Emeranko的《超级数据科学指南》的指导绘制预测图,但我很难做到这一点,因为我一直在犯这个错误 MemoryError: Unable to allocate 443. GiB for an array with shape (13500200, 4400) and data type float64 我正在运行的代码: from matplotlib.colors import ListedColormap X_set, y_set = X_train, y_t

我正试图按照Krill Emeranko的《超级数据科学指南》的指导绘制预测图,但我很难做到这一点,因为我一直在犯这个错误

MemoryError: Unable to allocate 443. GiB for an array with shape (13500200, 4400) and data type float64
我正在运行的代码:

from matplotlib.colors import ListedColormap

X_set, y_set = X_train, y_train
X1, X2 = np.meshgrid(np.arange(start = X_set[:, 0].min() -1, stop = X_set[:, 0].max() + 1, step = 0.01),
                     np.arange(start = X_set[:, 1].min() -1, stop = X_set[:, 1].max() + 1, step = 0.01))
plt.contourf(X1, X2, model.predict(np.array(np.array([X1.ravel(), X2.ravel()]).T).reshape(X1.shape),
                                        alpha = 0.75, cmap = ListedColormap(('red', 'green'))))
plt.xlim(X1.min(), X1.max())
plt.ylim(X2.min(), X2.max())

for i, j in enumerate(np.unique(y_set)):
     plt.scatter(X_set[y_set == j, 0], X_set[y_set == j, 1],
                      c = ListedColormap(('red', 'green'))(i), label = j)
plt.title('Logistic Regression (Training set)')
plt.xlabel('Age')
plt.ylabel('Estimated salary')
plt.legend()
plt.show()

错误消息是不言自明的。你的矩阵太大了,你真的需要一个更大的步长。使用
linspace(start=X_set[:,0].min()-1,stop=X_set[:,0].max()+1,num=200))
可以轻松地获得例如200个步骤。使用
arange
时,根据
X_set
中的值,步数可能过大或过小。问题:您的显示器有多少像素?如果您希望查看13500200x4400阵列,它一定非常危险。错误消息是不言自明的。你的矩阵太大了,你真的需要一个更大的步长。使用
linspace(start=X_set[:,0].min()-1,stop=X_set[:,0].max()+1,num=200))
可以轻松地获得例如200个步骤。使用
arange
时,根据
X_set
中的值,步数可能过大或过小。问题:您的显示器有多少像素?如果您希望看到13500200x4400阵列,它一定非常大