Practice lab: course 1, week 3, exercise 2 error

Hi @Mariyeh,

Since you are new to python, you definitely will need to spend more time on it. There is no other way out. Let’s start from scratch. I hope you still remember the following code for Exercise 2 which is what it was like when you first open the assignment notebook, before you edit it. I suggest you to start from this again.

# UNQ_C2
# GRADED FUNCTION: compute_cost
def compute_cost(X, y, w, b, lambda_= 1):
    """
    Computes the cost over all examples
    Args:
      X : (ndarray Shape (m,n)) data, m examples by n features
      y : (array_like Shape (m,)) target value 
      w : (array_like Shape (n,)) Values of parameters of the model      
      b : scalar Values of bias parameter of the model
      lambda_: unused placeholder
    Returns:
      total_cost: (scalar)         cost 
    """

    m, n = X.shape
    
    ### START CODE HERE ###
    
    ### END CODE HERE ### 

    return total_cost

First, I hope you will read this thread about indentation. There is nothing difficult, and it’s just like formatting. It’s like how you should format your code for python to understand your code.

Please read that thread, read the rules, read the how-to, then open some previous optional labs, compare what I said in the thread with what you see in those optional labs to build up some memory about when to indent and how to indent correctly.

If you still find it very difficult to accept, you might really need to switch to some python courses first, before you continue on the MLS. After you manage the indentation, please do exericse 2 again but follow the indentation rules.

Another hint for you is, you can go back to your course 1 week 2 exercise 1 to see how you implemented compute_cost there. They are not completely the same but I believe it will help you implement compute_cost in C1 W3 Ex2.

Cheers,
Raymond

1 Like