DLS Course 1,Week 2, Assignment 2 Error while executing model

AssertionError: Wrong shape for d[‘w’]. (2, 1) != (4, 1)
Can any one help me figure out the error

and the shape w is (2,1) from the beginning and my code worked perfectly during above instances

Well (2,1) may have been the relevant shape for earlier test cases, but it’s not correct for this one. All the code we are writing here is general and should be able to handle any number of features and samples. This type of error usually means you are referencing global variables from the local scope of the model function, instead of the actual parameters which were passed in.

I will re-check the entire code and try to modify it, So you are telling me that am using a global variable instead of the actual parameters to be passed. I will attach a screenshot of the code here I think I messed up while initializing w,b by calling a previous function.

{moderator edit - solution code removed}

Because dim = 2 which was declared earlier, should I initialize the value of w,b without calling ‘initialize_with_zeros(dim)’

Yes, there are several mistakes there:

  1. Where is the variable dim defined? It’s not local to this function, right?
  2. Where are the variables X and Y defined? Also not in the model function, right?
  3. No matter what value of num_iterations is passed into model, you will always do 100 iterations. That will not end well. You have treated the learning rate and print flag the same way. Defining a function is a completely different thing than calling (invoking) a function. You can just copy the definition of a function as a way to invoke it.

Please note that this course is not structured as a beginning programming course. You need to have pretty solid competence as a python programmer as a prerequisite in order to succeed here. If you are not familiar with the concept of variable “scope”, you should really consider putting this course on hold and taking an introductory python course first.

The way you compute the predictions is also wrong: you should be calling the predict function for that purpose.

Thanks, Paulin Now my code is perfect.I made the necessary modification as advised by you