C3W1 Exercise 6

Hi everyone, I’m getting this error for a very long time. can anyone please help me with this?


You have to define a value for a variable before you can use it.

I don’t understand what value to assign. I’m assigning 0 or 1 as a value but it’s not working and it’s no use to assign a random value like in gradient descent to initialize. can you please help me with this?

Sorry, I am not a mentor for that course.

okay. Actually, I’ve completed all 2 previous courses in this specialization and the rest of the week’s assignment in this course of statistics and prob. I couldn’t finish this specialization due to this very question. That’s why I need someone who can help me figure out where I’m making a mistake to understand this.

1 Like

What did you fill in for these codes below?

# Compute the relevant pdf given the distribution and the estimated parameters
                probability_f = None(None, None, None)

In first and third, i used the pdf_gaussian function that we defined previously and in second one, i used pmf_binomial function.

Me too, I’m stuck here as well. I just don’t see a way around the scoping issue. And if I set probability_f = 0 before match/case block, it doesn’t change after the loop and all values render as 0.

@Rod_Bennett and @Ashish_Raj , would you share with us how you constructed your match/case statements? From what you’ve written above, I speculate that the match/case statements were invalid, thus the probability_f object was not established.

Yes, this is how I coded the first two cases, third is the same …

{moderator edit: code removed}

I’m deleting the code, because sharing your code is not allowed.


  • How is probability_f defined if feature_name doesn’t match one of the cases?
  • What in your code could cause an incorrect feature to be passed to the match-case loop?

Hey @Ashish_Raj,
First of all, apologies for my previous incorrect response. I actually had the previous version of the assignment, and it was a little bit different than the current one, and as a result, my reply was based on that.

Coming to your issues, in your implementation of prob_of_X_given_C, you have used train_params (which happens to be a global variable) instead of params_dict (which is an argument passed to the function, that you are supposed to use). Additionally, for ear_head_ratio, you have computed probability_f, using a gaussian distribution, whereas, as per the assignment, you are supposed to use a uniform distribution.

Let us know if this helps.


Thank you so much guys @Tom_Pham @Elemento @TMosh @Rod_Bennett.
The Issue was that I was using X as an input for functions. It was the same X that the function received as an input which was a list. That’s why functions were not receiving any value for X.
for feature_val, feature_name in zip(X, features)” due to this function we can use the feature_val variable to insert the value of X in functions of this exercise. It was my mistake that I didn’t realize sooner. I wholeheartedly thank you guys for helping me. And now I finally cleared this specialization.

I’m happy to learn about your success! I used a different nomenclature for feature_val, in my case it was lowercase x. Perhaps others can see how the variable x is a subset of X :thinking:.