Machine Learning Specialization - DeepLearning.AI

Can someone pls tell me what is wrong with my code and fix it

Exercise 2 =

UNQ_C2

GRADED FUNCTION: compute_gradient

def compute_gradient(x, y, w, b):
“”"
Computes the gradient for linear regression
Args:
x (ndarray): Shape (m,) Input to the model (Population of cities)
y (ndarray): Shape (m,) Label (Actual profits for the cities)
w, b (scalar): Parameters of the model
Returns
dj_dw (scalar): The gradient of the cost w.r.t. the parameters w
dj_db (scalar): The gradient of the cost w.r.t. the parameter b
“”"

# Number of training examples
m = x.shape[0]

# You need to return the following variables correctly
dj_dw = 0
dj_db = 0

### START CODE HERE ### 

{moderator edit - solution code removed}

### END CODE HERE ### 
    
return dj_dw, dj_db

Hi, Sami.

Welcome to the course and to the forums!

Note that you filed this under the course “Machine Learning in Production” and you checked both the Coursera platform and the DLAI Learning Platform, but the question is about the Machine Learning Specialization and it looks like you are taking it on the DLAI platform. I used the little “edit pencil” on the title to fix those issues.

The other important thing to note is that the rules on the forums are that we can’t share solutions in a public thread. We also aren’t supposed to just fix the code for you in any case, but we can usually help by giving explanations about what the code needs to do.

So I edited your post to remove the actual solution code. But I did take the opportunity to look at it first and it all looks correct to me. So the next question is “why do you think that something is wrong?” Did you get an error message from running the notebook or from running the grader? If so, please show us the error message you got as a “copy/paste” or as a screenshot if it’s the grader output.

That’s the best way to ask for help with the programming assignments: instead of showing the code, please show us the error messages that you are getting. If we can’t figure out how to help based on that information, then there are non-public ways to actually look at your code. But we can cross that bridge when we get to it. :nerd_face: