部分资料来源于网络,仅做个人学习之用
https://blog.csdn.net/u013733326/article/details/79827273
(1)
# Visualize the data:
plt.scatter(X[0, :], X[1, :], c=Y, s=40, cmap=plt.cm.Spectral);
报错:
ValueError: 'c' argument has 1 elements, which is not acceptable for use with 'x' with size 400, 'y' with size 400.
解决:
修改为
plt.scatter(X[0, :], X[1, :], c=squeeze(Y), s=40, cmap=plt.cm.Spectral);
(2)
# Plot the decision boundary for logistic regression
plot_decision_boundary(lambda x: clf.predict(x), X, Y)
报错: ValueError: RGBA sequence should have length 3 or 4 During handling of the above exception, another exception occurred:
……
ValueError: 'c' argument has 1 elements, which is not acceptable for use with 'x' with size 400, 'y' with size 400.
解决:
将 plt.scatter(X[0, :], X[1, :], c=y, cmap=plt.cm.Spectral)
修改为 plt.scatter(X[0, :], X[1, :], c=squeeze(y), cmap=plt.cm.Spectral) 不起作用
将plot_decision_boundary函数中的:plot_decision_boundary(lambda x: clf.predict(x), X, Y)
修改为 plot_decision_boundary(lambda x: clf.predict(x), X, Y.ravel()) 成功解决
原因:c 需要一维的array