Coursera Machine Learning Course2 : UNQ_C2 # GRADED CELL: eval_cat_err def eval_cat_err(y, yhat):

When creating a post, please add:

  • Week # must be added in the tags option of the post.
  • Link to the classroom item you are referring to:
  • Description (include relevant info but please do not post solution code or your entire notebook):

y_hat does not have the same shape as y. Therefore, the Test fails. y_hat does not match with y hence test fails.

Either your y or y_hat has the wrong shape. Which one did you write the code for?

The files are already provided for the lab test. y_hat has the wrong shape (4,1), y is (800,)

Perhaps there are multiple tests, each using a different size of data set.
Your code should not assume a fixed size.

The code you add to eval_cat_err() should use the local variables y and yhat.

It should not directly reference the dataset loaded in section 4.1.

Hi TMosh

I did. But the test failed. Then I checked the shape in the code. The shapes must match. And it the array match in thest.What I do not understand

Also, the Hint shows the same code.

Basically the test data is not as stated in the comments:

  y    : (ndarray  Shape (m,) or (m,1))  target value of each example
  yhat : (ndarray  Shape (m,) or (m,1))  predicted value of each example

That function must work for any size of y and yhat variables. The function is a general-purpose tool.

I suspect the issue is that inside the eval_cat_err() function, you’re using some other variable besides y and yhat.

1 Like

I decided to submit. Failed. I am confused as all othere graded test I passed. I got the message:
Cell #20. Can’t compile the student’s code. Error: IndexError(‘index 2 is out of bounds for axis 0 with size 2’)

1] I do not have a Cell 20
2] Usually it goes through each graded test and says pass or fail. The above is all that I got. Tried rebooting the Kernal…still an issue

Here’s how the grader works:

It opens your notebook file and extracts the functions that are marked for grading.

It puts those into a template which runs a specific set of tests. These tests are not in the public domain. The grader’s tests are entirely separate from the tests that are built-into the notebook.

So the cell numbers that the grader reports are from its template, not from your notebook.

The grader does not give detailed Pass/Fail results for each test. The grader’s feedback messages are famously unhelpful.

Please check your forum personal messages for instructions.

{mentor edit - file removed}

Thank you

Sorry. My bad

See my reply on the personal message thread.

I just started using the arrays, assuming the comments at the top re shapes were correct --but were not. And that’s where I had problems

Note: We’re back on the public thread again, instead of the private discussion.

They are correct. In what way do you feel they are wrong?

To round out this thread so far:

It’s important to not use global variables within local functions.

For example, you should use the function arguments like ‘y’ and ‘yhat’ when adding add your code to the function.

Side-note:
It’s important to not add new cells to the notebook. This can confuse the grader.

1 Like

(800,)
800
(4, 1)
4