[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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章