C3_W1_KMeans_Assignment Variables Not Found


Could someone please help me get past these errors on assignment 1? It appears that the import functions at the beginning are not being compiled. It is therefore generating errors as shown in the attached images.

Hi there, the type of the ‘import numpy as ***’ cell should be ‘Code’, from the screenshot it seems to be changed to ‘Markdown’, can you try to change it back and rerun the ‘import **’ code cell?

Thank you very much for the quick response. I changed it to code and re-ran the cell. When I try to run the ‘find_closest_centroids’ function, I get the error shown in image. I also got the ‘name X not defined’ error. Could you please tell me what am I missing here?

No problem! For this type of error, I would suggest you find where the variable (e.g., ‘centroids’ here) appears the first time in the code file and see if it is properly defined or if the corresponding code cell is executed successfully.

Thank you. But, I’m sorry, I don’t seem to able to identify the error. I have followed a similar approach in all the previous assignments, but this particular exercise appears to be a little challenging to get through

Hi @jkashyap16,

I suggest you to spend a few minutes to read this indentation tips, and make correction to your code ;).


PS: we can’t post assignment code here so I am removing it.

I am having the same issue. But in my case, if I run the cell where the data are loaded first:

Load an example dataset that we will be using

X = load_data()
and then rerun the previous ones, the assignment continues with good results. The problem is when submitting the assignment, the auto-grading systems gets stuck with the following error:
Cell #4. Can’t compile the student’s code. Error: NameError(“name ‘X’ is not defined”)
And my assignment gets a “failed” score.
How do you resolve this? Please, help.
Thank you,

I’m going to close this thread, because it’s 4 months old and you also posted the question in a separate thread.