I have been working on the assignment and I am stuck at exercise 4 due to an error on the test function snippet
# Test your function
w1_unittest.test_predict_tweet(predict_tweet, freqs, theta)
I am getting the expected outputs in the previous snippets. but the snippet above fails with the following error:
The lines where it fails refer to ~/work/w1_unittest.py which is not part to the snippet where I wrote my code to solve the exercise.
Has anybody else encountered this and know a way to fix this?
Thanks in advance
I added a couple of print statements in my predict_tweet
function to show the type and shape of my return value. Here’s what I get:
type(y_pred) <class 'numpy.ndarray'>
y_pred.shape (1, 1)
I am happy -> 0.519275
My guess is that if you added the “type” print statement, you would see that your value is a python float instead of a numpy array.
Thank you for your quick response. I see where my error was. I fixed the type of the return and it works now.
Looking at instructions and my code, my only theory for how that error could happen is that you manually implemented the dot product x \cdot \theta that they show in the instructions as the input to sigmoid
. If you just use np.dot
, it should give you a 1 x 1 np.array as I showed.
1 Like