I am pretty much done with the assignment except the last step(putting the model together). I don’t see the input data for the model() parameters. All other functions have input values to test the function. Am I am missing something, any help is appreciated.
If you want to see how the model_test
function works, click “File → Open” and then open the file public_tests.py
. In python you can pass a function as an argument to another function. When model_test
calls model
, it passes arguments that it has just created.
Hmm, Now I go back to my course and I don’t see the programming assignment at all. It does show all other other sections of Week1 and it also says week1 is complete. I did not submit the programming assignment for week1. Help please…
There are no programming assignments in Course 1 Week 1. The first programming is in Week 2 and there are two of them there.
Nevermind, my bad, it is week2 assignment.
ok, I did not know that I need to refer to public_tests.py. I am still not clear about this method. I see target() called with parameters defined in model_test(). X_train is (4,7) - but I get an error -
ValueError: shapes (1,4) and (12288,209) not aligned: 4 (dim 1) != 12288 (dim 0)
I have w, b initialized to w, b = initialize_with_zeros(4).
Any help is appreciated. thanks.
Most likely ‘4’ is not always the correct value to use there.
You don’t need to refer to that code. I only pointed it out because you made the statement that model
was being called without parameters and I wanted to show you that was not a true statement.
As Tom says, 4 is not the general answer. It might work for that one case. The point here is that we are trying to write the code in a general way that will work with any sized inputs. So you need to base the sizes on the actual inputs that you get.
Strange, I changed to w, b = initialize_with_zeros(X_train.shape[0]) and now the error is gone. Though w values mismatch. Does it mean I need to fine-tune the model parameters to further minimize the cost function? But then logistic_regression_model = model() passed
train accuracy: 68.42105263157895 %
test accuracy: 34.0 %
This is a pretty bad score.
Tweaking the learning rate: I got -
train accuracy: 67.94258373205741 %
test accuracy: 84.0 %
Question: Do you give feedback on the assignment. Can I take it again, to get the best grade?
Thanks.
You don’t need to fine-tune the model. Don’t try this on any DLS assignments, otherwise, you will see unexpected errors.
If your w
value is not matching, it means your code is incorrect. Please share your full error here. However, if you changed any hyperparameters like learning_rate
, first grab the fresh copy of your assignment and do your code again, without changing any pre-written code.
You can grade your work as many times as you like. Only your highest score counts.
Here is the error:
AssertionError Traceback (most recent call last)
in
1 from public_tests import *
2
----> 3 model_test(model)
~/work/release/W2A2/public_tests.py in model_test(target)
131 assert type(d[‘w’]) == np.ndarray, f"Wrong type for d[‘w’]. {type(d[‘w’])} != np.ndarray"
132 assert d[‘w’].shape == (X.shape[0], 1), f"Wrong shape for d[‘w’]. {d[‘w’].shape} != {(X.shape[0], 1)}"
→ 133 assert np.allclose(d[‘w’], expected_output[‘w’]), f"Wrong values for d[‘w’]. {d[‘w’]} != {expected_output[‘w’]}"
134
135 assert np.allclose(d[‘b’], expected_output[‘b’]), f"Wrong values for d[‘b’]. {d[‘b’]} != {expected_output[‘b’]}"
AssertionError: Wrong values for d[‘w’]. [[ 0.08632165]
[-0.08227636]
[-0.11789439]
[ 0.1285291 ]] != [[ 0.08639757]
[-0.08231268]
[-0.11798927]
[ 0.12866053]]
Please note all the prior tests passed, I am kinda stuck with the final step - model()
Before answering this, first, tell me if have you reverted back to the original hyperparameters. If not, please get a clean copy of your notebook which I linked in my previous response.
Yes, I have got a fresh copy of the notebook.
How you are setting the num_iterations and learning_rate?
Moderator Edit: Solution Code Removed
First, why need to flatten X_train? Please follow the instructions and do not introduce anything new.
Secondly, num_iterations and learning_rate shouldn’t be 100 and 0.005, respectively. Check this recent post.
Thanks all the mentors, it is working now.