# prob_of_X_given_C

Hello,

I am stuck in this exercise and I get the following error when running thecheck of the function:

## ‘’’

TypeError Traceback (most recent call last)
Cell In[108], 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[107], line 42, in prob_of_X_given_C(X, features, breed, params_dict)
39 p = params_dict[breed][feature_name][“p”]
41 # Compute the relevant pmf given the distribution and the estimated parameters
—> 42 probability_f = pmf_binomial(X, n, p)
45 # Get the relevant parameters out of the params_dict dictionary
46 a = params_dict[breed][feature_name][“a”]

Cell In[100], line 16, in pmf_binomial(x, n, p)
14 print(x)
15 ### START CODE HERE ###
—> 16 pmf = (comb(n, x))(p**x)((1-p)**(n-x))
17 ### END CODE HERE ###
19 return pmf

TypeError: unsupported operand type(s) for -: ‘int’ and ‘list’
‘’’

However, the pmf_binomial function works ok:

``````def pmf_binomial(x, n, p):

# {moderator edit: code removed}
return pmf
``````

The prob_of_X_given_C function looks like that:

``````def prob_of_X_given_C(X, features, breed, params_dict):

if len(X) != len(features):
print("X and list of features should have the same length")
return 0

probability = 1.0

### START CODE HERE ###

# {moderator edit: code removed}

### END CODE HERE ###

return probability
``````

I recommend you use the class method that computes this for you.

https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.binom.html

Also, please don’t post your code on the forum. That’s not allowed by the Code of Conduct.
Posting your error messages is fine, even if they contain pieces of your code.

if a mentor needs to see your code, we’ll contact you with instructions.

Thank you. I have replaced with the binom method from above, there is no error anymore but I still get 0/10 points out of this cell (prob_of_X_given_C). Any hints where the problem is?

The check gives the following output:
Example dog has breed 1 and features: height = 28.63, weight = 21.56, bark_days = 13.00, ear_head_ratio = 0.27

30
[28.625469068290815, 21.563672670727037, 13.0, 0.27378731851535243]
Probability of these features if dog is classified as breed 0: [0. 0. 0. 0.]
30
[28.625469068290815, 21.563672670727037, 13.0, 0.27378731851535243]
Probability of these features if dog is classified as breed 1: [0. 0. 0. 0.]
30
[28.625469068290815, 21.563672670727037, 13.0, 0.27378731851535243]
Probability of these features if dog is classified as breed 2: [0. 0. 0. 0.]
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

In the grader feedback, click on the > and it will display the reason the grader is unhappy.