Week 1 anomaly detection -- pass with 100% but it still isn't right

I’ve just completed week 1, including the anomaly detection lab. I pass with 100% and my function passes all tests on the graded portion, but does not produce the output expected for the multivariate portion

My estimate_gaussian is simple and vectorized

{moderator edit: code removed}

I spent a lot of time trying to find a vectorized implementation for select_threshold so that I could avoid running a pile of if/then statements, but had to move on. I ended up with the following

{moderator edit: code removed}

Any idea why it passes but produces incorrect results on the multivariate portion?

I’m not going to debug your code (in part because posting your code is not allowed by the Code of Conduct).

But I will provide some guidance.

  • Are you certain that val() gives the same results as are given in the hints? You didn’t show your test results.

In general you’re writing way more code than is necessary.

  • You don’t need an iterator to compute the predictions. A simple logical comparison between p_val and epsilon will handle it.

  • To compute tp, fp, and fn, you only need np.sum() with a vector of 1’s and 0’s, computed by the and (&&) of (predictions == ?) && (y_val == ?). The values in the ? will be either 0 or 1, depending on the condition you’re computing.

  • Then you can compute prec, rec, and F1 using some simple algebra that combines tp, fp, and fn.