22.02.2024 Views

Daniel Voigt Godoy - Deep Learning with PyTorch Step-by-Step A Beginner’s Guide-leanpub

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

true_b = 1

true_w = 2

N = 100

# Data Generation

np.random.seed(42)

# We divide w by 10

bad_w = true_w / 10

# And multiply x by 10

bad_x = np.random.rand(N, 1) * 10

# So, the net effect on y is zero - it is still

# the same as before

y = true_b + bad_w * bad_x + (.1 * np.random.randn(N, 1))

Then, I performed the same split as before for both original and bad datasets and

plotted the training sets side-by-side, as you can see below:

# Generates train and validation sets

# It uses the same train_idx and val_idx as before,

# but it applies to bad_x

bad_x_train, y_train = bad_x[train_idx], y[train_idx]

bad_x_val, y_val = bad_x[val_idx], y[val_idx]

Figure 0.13 - Same data, different scales for feature x

Step 4 - Update the Parameters | 49

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!