Week 1 Exercise 5

I am having a lot of trouble with exercise 5 of the week 1 assignment. Do you have any idea why my output looks like this?

Distribution parameters for training split:

{0: {‘breed’: {‘bark_days’: (30, 0.0),
‘ear_head_ratio’: (0, 0),
‘height’: (0.0, 0.0),
‘weight’: (0.0, 0.0)}},
1: {‘breed’: {‘bark_days’: (30, 0.03333333333333333),
‘ear_head_ratio’: (1, 1),
‘height’: (1.0, 0.0),
‘weight’: (1.0, 0.0)}},
2: {‘breed’: {‘bark_days’: (30, 0.06666666666666667),
‘ear_head_ratio’: (2, 2),
‘height’: (2.0, 0.0),
‘weight’: (2.0, 0.0)}}}

Probability of each class for training split:

{‘breed’: 0.3461697722567288}

Try using these guidelines from the exercise ( Take note of lines where you match case and use appropriate distribution) :

Since the interpretation and way of computing these parameters has not been covered in the lectures, the assignment provides functions that can accomplish this for you. These have already been imported into this environment and are called:


Yes, I used those functions. I think the problem is my inner for loop. I am not sure how to iterate there. Iterating through df_breed.columns gives an error, so I am not sure what to do.

Look at the arguments that feed into compute_training_params
Try to use that to iterate and also it should be used to match

        df (pandas.DataFrame): The dataframe containing the training data.
        features (list): A list of feature names to consider.

# Loop over the columns of the sliced dataframe

So try to get columns as list then loop (& match) through those.
Also, consider

m, s = estimate_gaussian_params(np.array([26.31, 32.45, 14.99]))

So, estimate_gaussian_params( ) takes an array as argument. Think of your dataframe column

1 Like

I figured out Exercise 5, thanks so much!