Don’t add an extra line of code. Check lines 53 and 56 (in your error), both are the same. 53 is unnecessary.

i added that to each case for scoping purposes, but either way the error is the same - that’s not causing the error. Do I need to initialize the probability_f variable in the global scope before the match block?

Interesting, that’s a little different than the starter code I had at the beginning, but it doesn’t make much difference. The problem is that if I try to multiply probability *= probability_f there’s a scoping problem. Anyway, thanks for your help.

Send me your code in a private message. Click my name and message.

I deleted my previous response as the assignment file is updated and I was checking the old one.

I am having the same problem

UnboundLocalError Traceback (most recent call last)

Cell In[90], line 7

4 example_breed = df_test[[“breed”]].loc[0][“breed”]

5 print(f"Example dog has breed {example_breed} and features: height = {example_dog[‘height’]:.2f}, weight = {example_dog[‘weight’]:.2f}, bark_days = {example_dog[‘bark_days’]:.2f}, ear_head_ratio = {example_dog[‘ear_head_ratio’]:.2f}\n")

----> 7 print(f"Probability of these features if dog is classified as breed 0: {prob_of_X_given_C([*example_dog], FEATURES, 0, train_params)}“)

8 print(f"Probability of these features if dog is classified as breed 1: {prob_of_X_given_C([*example_dog], FEATURES, 1, train_params)}”)

9 print(f"Probability of these features if dog is classified as breed 2: {prob_of_X_given_C([*example_dog], FEATURES, 2, train_params)}")

Cell In[89], line 81, in prob_of_X_given_C(X, features, breed, params_dict)

64 probability_f = pdf_uniform(X, a, b-a)

68 # Multiply by probability of current feature

69 #probability *= None

70 #probability *= probability_f

(…)

79 #probability *= probability_f(feature_val)

80 #probability *= probability_f*feature_val

—> 81 probability *= probability_f

83 ### END CODE HERE ###

85 return probability

UnboundLocalError: local variable ‘probability_f’ referenced before assignment

I also tried feature_val but the test results do not match

Example dog has breed 1 and features: height = 28.63, weight = 21.56, bark_days = 13.00, ear_head_ratio = 0.27

Probability of these features if dog is classified as breed 0: 2197.009947435549

Probability of these features if dog is classified as breed 1: 2197.009947435549

Probability of these features if dog is classified as breed 2: 2197.009947435549

**Expected Output**

```
Example dog has breed 1 and features: height = 28.63, weight = 21.56, bark_days = 13.00, ear_head_ratio = 0.27
Probability of these features if dog is classified as breed 0: 6.989632718589114e-11
Probability of these features if dog is classified as breed 1: 0.0038267778327024894
Probability of these features if dog is classified as breed 2: 7.959172138800559e-08
```

Hi Alison,

Make sure you’re using all of the variables correctly throughout the match cases:

`feature_val, feature_name in zip(X, features)`

Thank you for taking the time to share your insight.

I appreciate it!

Alison

Ah, one other hint if you haven’t solved it yet … you may need to use [breed] as a variable in the match cases.

I will do both. Thank you very much