Issues try lab session in my own enviroment

I try to run the Logistic Regression with a Neural Network mindset exercise on my computer, I did recreate all folders as shown in the course environment but I having the following error in run 2 when loading the data

Loading the data (cat/non-cat)

train_set_x_orig, train_set_y, test_set_x_orig, test_set_y, classes = load_dataset()

NameError Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_28684/377641723.py in
1 # Loading the data (cat/non-cat)
----> 2 train_set_x_orig, train_set_y, test_set_x_orig, test_set_y, classes = load_dataset()

NameError: name ‘load_dataset’ is not defined

I got the function load_dataset() as defined in lr_utils.
I don’t see any errors when executing the following line in run 1

from lr_utils import load_dataset


import numpy as np
import h5py

def load_dataset():
train_dataset = h5py.File(‘datasets/train_catvnoncat.h5’, “r”)
train_set_x_orig = np.array(train_dataset[“train_set_x”][:]) # your train set features
train_set_y_orig = np.array(train_dataset[“train_set_y”][:]) # your train set labels

test_dataset = h5py.File('datasets/test_catvnoncat.h5', "r")
test_set_x_orig = np.array(test_dataset["test_set_x"][:]) # your test set features
test_set_y_orig = np.array(test_dataset["test_set_y"][:]) # your test set labels

classes = np.array(test_dataset["list_classes"][:]) # the list of classes

train_set_y_orig = train_set_y_orig.reshape((1, train_set_y_orig.shape[0]))
test_set_y_orig = test_set_y_orig.reshape((1, test_set_y_orig.shape[0]))

return train_set_x_orig, train_set_y_orig, test_set_x_orig, test_set_y_orig, classes

Hey @Alcalafrancisco,

Have you run the cell which imports the load_dataset function?

1 Like

Right! That was going to be my question as well. The point is that you have to understand how the “runtime state” of the notebooks work: anytime you close and reopen the notebook or do any operation that restarts the Kernel, you need to rerun all the previous cells to create any variables or functions that are defined or imported in those cells. Anytime you get “routine name not defined”, try “Cell → Run All Above” and then try it again.

As you’ve discovered, running locally requires that you bring down all the files associated with each assignment, not just the notebook itself. There are not complete instructions for doing that, but here’s a thread that gives some guidance. One important thing to realize is that the article on the Coursera Help Center about downloading doesn’t really cover the way things work in these courses.

Then the next layer of issues is that you need to install the correct versions of all the python and other packages that the notebooks depend on. Here’s a thread which talks about that, but is (again) not a complete recipe.

Thanks all, I was able to make it work :slight_smile: