I have been looking through the labs to see if I can find examples for Q4. Because of the two for loops:
for i in range (m):
for j in range (n):
That we are required to loop through X and w, and then cast b, rather than use dot.product.
I am getting the following error message and am stuck.
It looks like the issue arises from how you’re handling the bias term b and the term z_wb in your predict function. Specifically, the error TypeError: 'float' object is not iterable indicates that you might be attempting to add a scalar value (your bias term b) to a NumPy array (probably z_wb) in a way that Python doesn’t recognize as valid. The way you wrote z_wb += b may have confused if z_wb is not initialized properly, or if the dimensions of b and z_wb are incompatible.
As you mentioned, there are two loops iterating over m (number of examples) and n (number of features). You need to make sure that you’re calculating z_wb as a scalar for each example i in m. You can achieve this by summing over the dot product of the weights and features and adding the bias b afterward.
The hint about calculating f_wb is suggesting you follow the same process as in the cost function:
- Calculate the linear combination of inputs and parameters z_wb = np.dot(...) + ... where X[i] corresponds to the ith example
- Calculate the sigmoid of the linear combination: f_wb = sigmoid(z_wb)
As @danieljhand mentioned, this error indicates that there is probably a small typo or syntax error somewhere in the lines above it. Here are a few things to check:
Make sure that cost_without_reg and reg_cost are defined correctly.
Make sure the parentheses in reg_cost are properly enclosed.