Week 2 Practice Lab: Linear Regression *Need Help*

Hello,

I am struggling with the graded practice lab. I have followed the hints and the coding, but I am getting a 0% correct when I go to submit the lab. I look at the test code result, it is unclear where my issue is. Here is an example:


AssertionError Traceback (most recent call last)
in
9 # Public tests
10 from public_tests import *
—> 11 compute_cost_test(compute_cost)

~/work/public_tests.py in compute_cost_test(target)
17 initial_b = 1.0
18 cost = target(x, y, initial_w, initial_b)
—> 19 assert cost == 2, f"Case 2: Cost must be 2 but got {cost}"
20
21 # print(“Using X with shape (5, 1)”)

AssertionError: Case 2: Cost must be 2 but got 0.5

here is my actual coding:

# UNQ_C1
# GRADED FUNCTION: compute_cost

def compute_cost(x, y, w, b): 

# moderator edit: code removed

Can someone take a look and provide some guidance? I have similar issues on the gradient descent problem.

This is all new to me and I do not have a very clear understanding yet.

I appreciate everyone’s time and assistance.

Best regards,

Rich Kline

Please don’t post your code on the forum. That’s not allowed by the Code of Conduct.
If a mentor needs to see your code, we’ll contact you with instructions via a private message.

I will edit your post to remove the code.

Tip: The code in your for-loop is overwriting the ‘cost’ value on every iteration, but it never accumulates it into the cost_sum. Check whether your code is using indentation correctly.

My apologies, I wasn’t aware of that as I’ve seen other coding in prior posts. I will be sure to not let it happen again.

Thank you for the feedback. I will take a look at my coding and troubleshoot the issues. Thank you again! I appreciate it.

We try to edit those out as quickly as possible.