C3 W1 A1 Ex 6: prob_of_X_given_C

Hello! I hope you are doing well.

This query is about C3 W1 A1 Ex 6: prob_of_X_given_C.

We have given that you just need to compute the appropriate PDF for each feature by passing the estimated parameters of that feature to the corresponding PDF computation function.

Code structure is:

### START CODE HERE ###
    
    for None, None in zip(None, None):
        
        # Get the relevant parameters from params_dict 
        params = params_dict[None][None]

        match None:
            # You can add add as many case statements as you see fit
            case "height" | "weight": 
                # Compute the relevant pdf given the distribution and the estimated parameters
                probability_f = None(None, None, None)
  1. I did x and feature in zip of X and features.
  2. I used breed and feature for [None][None] of params_dict

For the case of height or weight, I am using the Gaussian PDF which takes the x, mu, and sigma as the argument. So, my question is, how to pass the mu and sigma?

I print out the params_dict but didn’t get any hint:
params_dict: {2: {'height': Index(['height', 'weight', 'bark_days', 'ear_head_ratio'], dtype='object'), 'weight': Index(['height', 'weight', 'bark_days', 'ear_head_ratio'], dtype='object'), 'bark_days': Index(['height', 'weight', 'bark_days', 'ear_head_ratio'], dtype='object'), 'ear_head_ratio': Index(['height', 'weight', 'bark_days', 'ear_head_ratio'], dtype='object')}, 0: {'height': Index(['height', 'weight', 'bark_days', 'ear_head_ratio'], dtype='object'), 'weight': Index(['height', 'weight', 'bark_days', 'ear_head_ratio'], dtype='object'), 'bark_days': Index(['height', 'weight', 'bark_days', 'ear_head_ratio'], dtype='object'), 'ear_head_ratio': Index(['height', 'weight', 'bark_days', 'ear_head_ratio'], dtype='object')}, 1: {'height': Index(['height', 'weight', 'bark_days', 'ear_head_ratio'], dtype='object'), 'weight': Index(['height', 'weight', 'bark_days', 'ear_head_ratio'], dtype='object'), 'bark_days': Index(['height', 'weight', 'bark_days', 'ear_head_ratio'], dtype='object'), 'ear_head_ratio': Index(['height', 'weight', 'bark_days', 'ear_head_ratio'], dtype='object')}}

Your guidance is highly appreciated.

Best,
Saif.

1 Like

Hi @saifkhanengr! In that case you can do params.mu and params.sigma to get those values.

1 Like

I am getting this error with params.mu

Hmm that is weird. Can you sent me your notebook in a DM so I can take a look?

Thank you for your support. I sent you my notebook in .ipynb format. Feel free to take your time. I will come back in 12 hours as its night at my place.

The issue is in the compute_training_params. The parameters are saved using a dictionary but they should be stored inside the relevant dataclass (params_gaussian for height and weight and so on). Also the value of inner_dict for every column is being overwritten by df_breed.columns.

Yeah, that was a problem. Thank you for your guidance.

1 Like

Hello to the community,

I’m having a issue with multiplying the probability of the features of interest to the final probability. This is was due to probability_f not being a global variable. Do you mind trouble shooting this error for? Helping me figure out what I did wrong when writing this function would be much appreciated. Thanks!



I did uncomment the other the functions starting with “pdf” and the variable assignments prior.

Hello @a-zarta! Did you notice something strange?

Need to update the assignment so students do their code, instead of uncommenting. You got it, right?

Best,
Saif.

Those comments weren’t part of the assignment, I added them. The comments assigning the parameters for the PDF function are actually uncommented and used, the screen shot I sent was misoinformative. The issue I’m having is not being ably to assign a local variable global
?

oh, I see. Thanks for clarifying.

Hi Ashrah, did you find a solution to this question? I am also trying to figure out what variable to use for probabilities *= None

You have to use the relevant pdf/pmf . Just the above three cases above this line of code.

but when i multiply by probabilities_f it doesn’t work because probabilities_f is not global scoped.

What is probabilities_f? Check the spelling again.

I meant probability_f

And what is “probabilities”? Again, spelling.

Shar your full error please.