[DeepLearning]吴恩达Coursera课后作业

部分资料来源于网络,仅做个人学习之用

吴恩达课后作业整合

https://blog.csdn.net/u013733326/article/details/79827273


问题集合

课程1_第3周_编程作业

(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

你可能感兴趣的:([DeepLearning]吴恩达Coursera课后作业)