C3_W1_KMeans_Assignment compute centroids function

I did exactly as in hints but its giving an error as below

AssertionError Traceback (most recent call last)
in
5
6 # UNIT TEST
----> 7 compute_centroids_test(compute_centroids)

~/work/public_tests.py in compute_centroids_test(target)
13
14 assert type(centroids) == np.ndarray, “Wrong type”
—> 15 assert centroids.shape == (K, X.shape[1]), f"Wrong shape. Expected: {(len(X),)} got: {idx.shape}"
16 assert np.allclose(centroids, expected_centroids), f"Wrong values. Expected: {expected_centroids}, got: {centroids}"
17

AssertionError: Wrong shape. Expected: (7,) got: (7,)

My code in the function

Can someone help me to fix this.

Hey @U_Y_G_Milan_Kavinda,
In the below line of code,

centroids = np.mean(points, axis = 0)

You are supposed to define the centroid for the k^{th} cluster in the k^{th} iteration of the loop, but you have defined all the centroids in every iteration of the loop. In other words, it is supposed to be:

centroids[k] = np.mean(points, axis = 0)

I hope this helps.

P.S. - Posting code publicly is against the community guidelines. If a mentor needs to take a look at your code, he/she will ask you to DM it. Please refrain from doing so in the future.

Cheers,
Elemento

Thankyou very much, sorry for the violation Will not do that again