Practice lab: C1_W2_Linear Regression load data()

Hi, in the Practice lab: C1_W2_Linear Regression, we need to use the function load_data():
x_train, y_train = load_data()

I downloaded this lab and all the lab files to my local pc and working directory and then uploaded this lab file into my Jupyter Notebook on my local pc. Afterwards, I run the code:

x_train, y_train = load_data()

However, I receive a NameError: name ‘load_data’ is not defined.

In the lab files, I cannot find any file which defines the function load_data(). My question is, where to find the file defining load_data(), so that I can dowload it? Thanks!

Hello @Xingyi_Shi
Kindly make sure that you run all the cells from the beginning once.

1 Like

Hello @Xingyi_Shi

load_data() is in utils.py

As a general guideline, if you are downloading the notebook to your local machine, do not pick and choose files from your Coursera folder. Download ALL the files and folders from your Coursera workspace to your local environment. You can do this by clicking on “lab files” at the top right of your notebook and then “download all files” - This way the “relative” directory structure of all the folders will be maintained as referenced in the notebook.

Thanks to you both. I did it all again. Now it works. Thanks!

Yes, they are. However, today I tried again. No images could be rendered.

Now a second question: C1_W3_Lab02_Sigmoid_function_soln:

from lab_utils_common import draw_vthresh

ImportError: cannot import name ‘sigmoid’ from ‘lab_utils_common’ (C:\XingyiShi\anaconda3\lab_utils_common.py)

However, all the lab files are downloaded into local work directory. What’s wrong here?

Then I opened lab_utils_common.py in Thonny, run it, I recieved an error:
ModuleNotFoundError: No module named ‘ipywidgets’

My question is, ist ipywidgets a package? I actually installed in anaconda prompt:

conda install ipywidgets
The result is “# All requested packages already installed.”

so I don’t understand why I still receive an ImportError.

@Xingyi_Shi

In which folder is your notebook?

Can you send me the output of the command

import os
print(“Content of working directory: {0}”.format(os.listdir()))

Your command yesterday:

import os
print(“Current working directory: {0}”.format(os.getcwd()))
os.chdir(‘C:/Xingyi_Python/MachineLearningSpecilization/work/’)
print(“Current working directory: {0}”.format(os.getcwd()))

Output:
Current working directory: C:\Xingyi_Python\MachineLearningSpecilization\work
Current working directory: C:\Xingyi_Python\MachineLearningSpecilization\work

print(“Content of working directory: {0}”.format(os.listdir()))

Content of working directory: [‘.ipynb_checkpoints’, ‘archive’, ‘betaversion’, ‘C1W1L1_Markdown.PNG’, ‘C1W1L1_Run.PNG’, ‘C1W1L1_Tour.PNG’, ‘C1_W1_L3_S1_Lecture_b.png’, ‘C1_W1_L3_S1_model.png’, ‘C1_W1_L3_S1_trainingdata.png’, ‘C1_W1_L3_S2_Lecture_b.png’, ‘C1_W1_L4_S1_Lecture_GD.png’, ‘C1_W1_Lab01_Python_Jupyter_Soln.ipynb’, ‘C1_W1_Lab02_Course_Preview_Soln.ipynb’, ‘C1_W1_Lab02_GoalOfRegression.PNG’, ‘C1_W1_Lab03_alpha_too_big.PNG’, ‘C1_W1_Lab03_lecture_learningrate.PNG’, ‘C1_W1_Lab03_lecture_slopes.PNG’, ‘C1_W1_Lab03_Model_Representation_Soln.ipynb’, ‘C1_W1_Lab04_Cost_function_Soln.ipynb’, ‘C1_W1_Lab05_Gradient_Descent_Soln.ipynb’, ‘C1_W2_Lab01_Python_Numpy_Vectorization_Soln.ipynb’, ‘C1_W2_Lab02_Multiple_Variable_Soln.ipynb’, ‘C1_W2_Lab03_Feature_Scaling_and_Learning_Rate_Soln.ipynb’, ‘C1_W2_Lab04_FeatEng_PolyReg_Soln.ipynb’, ‘C1_W2_Lab05_Sklearn_GD_Soln.ipynb’, ‘C1_W2_Lab06_Sklearn_Normal_Soln.ipynb’, ‘C1_W2_Linear_Regression.ipynb’, ‘C1_W3_Lab01_Classification_Soln.ipynb’, ‘C1_W3_Lab02_Sigmoid_function_Soln.ipynb’, ‘C1_W3_Lab03_Decision_Boundary_Soln.ipynb’, ‘C1_W3_Lab04_LogisticLoss_Soln.ipynb’, ‘C1_W3_Lab05_Cost_Function_Soln.ipynb’, ‘C1_W3_Lab06_Gradient_Descent_Soln.ipynb’, ‘C1_W3_Lab07_Scikit_Learn_Soln.ipynb’, ‘C1_W3_Lab08_Overfitting_Soln.ipynb’, ‘C1_W3_Lab09_Regularization_Soln.ipynb’, ‘data’, ‘data.txt’, ‘deeplearning.mplstyle’, ‘images’, ‘lab_utils_common.py’, ‘lab_utils_multi.py’, ‘lab_utils_uni.py’, ‘plt_logistic_loss.py’, ‘plt_one_addpt_onclick.py’, ‘plt_overfit.py’, ‘plt_quad_logistic.py’, ‘pre_414’, ‘public_tests.py’, ‘utils.py’, ‘pycache’]

Well, this could be part of the problem. You have multiple notebooks, supporting files and folders from different weeks sitting in the same folder. How will we know if you have overwritten a file or folder. For example, the images folder will be different for different notebooks.

I would suggest not to put everything under the work folder. You will need to create separate sub-folders under the work folder. Each time you go to “lab files” and do “download all files” , put the entire content into 1 separate folder under “work”. Next time you download something else, put it into another folder under “work”

Oh, do you mean I need to set up a new working directory for each lab and save notbooks and their lab files in different working directories?

in the subfolder ./images/, all png files are stored there. e.g. ./images/C1_W3_LogisticRegression_left.png

However, I run

The result ist still blank.

Yes, you need a separate working directory. It cannot all be under work, because files/folders will get overwritten.

Whatever you get from “lab files” → “download all files” can stay in 1 folder. Next time you download another practise lab from another week, you have to put it into another folder. Do not mix them.

1 Like

But you are running:

./images/C1_W3_LogisticRegression_left.png has nothing to do with this notebook. This image is for another notebook from Week 3

You are right. This image is for C1_W3_Lab02_Sigmoid_function_Soln. However, it does not matter. in neither notbook image can be rendered, even if the image is stored in the images subfolder.

I mentioned this notbook C1_W3_Lab02_Sigmoid_function_Soln is because I have a problem in this notbook today as mentioned in my today’s ealier chat:

Now a second question: C1_W3_Lab02_Sigmoid_function_soln:

from lab_utils_common import draw_vthresh

ImportError: cannot import name ‘sigmoid’ from ‘lab_utils_common’ (C:\XingyiShi\anaconda3\lab_utils_common.py)

However, all the lab files are downloaded into local work directory. What’s wrong here?
Then I opened lab_utils_common.py in Thonny, run it, I recieved an error:
ModuleNotFoundError: No module named ‘ipywidgets’

My question is, ist ipywidgets a package? I actually installed in anaconda prompt:

conda install ipywidgets
The result is “# All requested packages already installed.”

so I don’t understand why I still receive an ImportError.

May i request that you download all the files once again from “lab files” but this time put it into a new folder and extract all the files in this new folder. Do not put it directly under Ananconda3

Your working folder is:C:\Xingyi_Python\MachineLearningSpecilization\work
but your lab_utils_common.py is in C:\XingyiShi\anaconda3\lab_utils_common.py

This will not work!!

Sure. sorry that I did not tried by myself. Now I will download the C1_W3_Lab02_Sigmoid_function and its lab files into a seperate folder and run again.

Now I saved all the lab files for C1_W3_Lab02_Sigmoid_function_Soln into the work directory

C:\Xingyi_Python\MachineLearningSpecilization\work\C1_W3_Lab02_Sigmoid_function_Soln

and run
from plt_one_addpt_onclick import plt_one_addpt_onclick
from lab_utils_common import draw_vthresh

No error message any more. It works.

I run
***img align=“left” src=“./images/C1_W3_LogisticRegression_left.png” style=" width:300px;
***padding: 10px; "

still blank! Really strange! C1_W3_LogisticRegression_left.png is saved in C:\Xingyi_Python\MachineLearningSpecilization\work\C1_W3_Lab02_Sigmoid_function_Soln\images
I can open this file and see the picture.

Wonderful!! So, you are set then. Keep this experience in mind whenever it throws error messages that something is not found or missing - It won’t do that unless you have put files and folders where it cannot find it.

And if you see yourself wasting time to fix issues in your local environment, then come back to the coursera enivrornment, finish the work there, and then go back to troubleshooting - Google the error and you should find suggestions.

Good Luck!

Thank you very much for your help!