Week 1 - Practice Lab 2 Error

Hello Everyone,

am having a problem with implementing the ‘estimate_gaussian’ function in the nested loops form, when i get to the testing part, it fails and throws an error, i’ve looked into the code several times trying to debug it but so far i don’t see where the problem is, can anybody help ?

m, n = X.shape
mu = np.zeros(n)
var = np.zeros(n)

for i in range(n):
    for j in range(m):
        mu[i] += X[j,i]
    for k in range(m):
        var[i] += pow(X[k,i] - mu[i], 2)
mu *= 1/m
var *= 1/m

Error:

Hi @Bassil_Orabii

you didn’t want to loop over features(columns (n)) as you want to get the mean and variance over every columns so you want to do it with only one loop over m or you can didn’t use it and check the hint

please make sure you divide mu by m before you calculating variance

Thanks!
Abdelrahman

Yeah exactly i didn’t divide mu by m before calculating variance, thank you so much for the help abdelrahman !