- Course 1
- Assignment 3 error 1
- Assignment 3 error 2
- Course 2
- Assignment 1 error 1
Course 1
Assignment 3 error 1
問題代碼:
# Visualize the data:plt.scatter(X[0, :], X[1, :], c=Y, s=40, cmap=plt.cm.Spectral);12
執行後報錯:
ValueError: c of shape (1, 400) not acceptable as a color sequence for x with size 400, y with size 400
需要將上面的代碼修改如下:
# Visualize the data:plt.scatter(X[0, :], X[1, :], c=Y.flatten(), s=40, cmap=plt.cm.Spectral);12
然後就可以看到這朵花了
Assignment 3 error 2
問題代碼:
X_assess, parameters = forward_propagation_test_case()A2, cache = forward_propagation(X_assess, parameters)# Note: we use the mean here just to make sure that your output matches ours. print(np.mean(cache['Z1']) ,np.mean(cache['A1']),np.mean(cache['Z2']),np.mean(cache['A2']))1234
執行後報錯:
ipykernel_launcher.py:20: RuntimeWarning: divide by zero encountered in log
ipykernel_launcher.py:20: RuntimeWarning: invalid value encountered in add
檢查你的計算前饋網絡時候使用的激活函數,將forward_propagation函數的計算A2的代碼修改如下:
Z1 = np.dot(W1,X)+b1A1 = np.tanh(Z1)Z2 = np.dot(W2,A1)+b2A2 = sigmoid(Z2)1234
並且注意,如果這裡得不到一致的結果,直接會影響最後的nn_model函數,構建不出恰當的模型
Course 2
Assignment 1 error 1
可能會在很多地方看到類似這樣的報錯
ValueError: c of shape (1, 300) not acceptable as a color sequence for x with size 300, y with size 300
這是由於提供的代碼中,很多地方都是plt.scatter函數的參數 c 出問題,下面不一一列舉,簡述個人遇到的需要修改的地方:
修改reg_utils.py:
# 324行plt.scatter(X[0, :], X[1, :], c=np.squeeze(y), cmap=plt.cm.Spectral)# 334行plt.scatter(train_X[0, :], train_X[1, :], c=np.squeeze(train_Y), s=40, cmap=plt.cm.Spectral);1234
閱讀更多 程序員小新人學習 的文章