Course 4 Week 2: Predicting time series

Hello everyone,

I’m working on the graded assignment in Week 2(Programming Assignment: Forecasting Using Neural Networks).
Here’s my implementation of create_model:

# GRADED FUNCTION: create_model
def create_model(window_size):
    # code removed by mentor
    return model

When I test with:

example_batch = train_dataset.take(1)
model = create_model(WINDOW_SIZE)

try:
    model.evaluate(example_batch, verbose=False)
except:
    print("Your model is not compatible with the dataset.")

I still get:

Your model is not compatible with the dataset you defined earlier.

I also checked shapes:

print(model.input_shape)   # (None, WINDOW_SIZE)
print(model.output_shape)  # (None, 1)

They look fine, but I still get the error.

Question:
Is the issue in the model definition or could it be in how I built train_dataset with windowed_dataset? What’s the correct expected input/output shape for this assignment?

Thanks in advance :folded_hands:

Model definition looks good. Please check the shapes of the windowed dataset. Each row of the input dataset consists of 10 input features and 1 output feature. creating a temporary jupyter notebook cell and invoking model.evaluate(example_batch, verbose=False) will help figure out the problem.

pass the input shape as string instead of tuple.

is this the complete output you got when run test cell after create model grade function codes?

Also remember the model is using the dataset fromyout previous grade function, where you need to check if the slicing is done in appropriate windows. While slicing, drop_reminder is an important parameter to consider

drop_remainder (Optional.) A tf.bool scalar tf.Tensor, representing whether the last batch should be dropped in the case it has fewer than batch_size elements; the default behavior is not to drop the smaller batch.

make sure you are using correct tensorflow dataset function recall from series to create your dataset

Further make sure when you are splitting dataset into labels and features, you used the correct variable recall to do the splitting.

Let us know if you are still stuck, at which time one of us need to review your codes for previous grade function windowed_dataset

hi , When I tried to print the input and output shapes of my model with:

print(f'Model input shape: {model.input_shape}')
print(f'Model output shape: {model.output_shape}')

I got the error:

NameError: name 'model' is not defined

In fact, this is the same error I got right after the message:
"Your model is not compatible with the dataset you defined earlier. Check that the loss function and last layer are compatible with one another."

So the real issue is that model is not being recognized in that cell, even though I defined it inside the create_model function.

yeah actually i got this error after the message “Your model is not compatible with the dataset you defined earlier. Check that the loss function and last layer are compatible with one another.” and unfortunately , i tried all you said before but nothing changed

model should be defined when you invoke the evaluate function or refer any properties on it like model.input_shape

Try this:

example_batch = train_dataset.take(1)
model = create_model(WINDOW_SIZE)
print(model.input_shape)   # (None, WINDOW_SIZE)
print(model.output_shape)  # (None, 1)
model.evaluate(example_batch, verbose=False) 

Also, what’s the output when testing windowed_dataset by invoking the cell that follows its definition?


Cell In[49], line 5
    model.evaluate(example_batch, verbose=False
                                               ^
SyntaxError: incomplete input

The output of window_dataset is like the expected output :

batch_of_features has type: <class 'tensorflow.python.framework.ops.EagerTensor'>

batch_of_labels has type: <class 'tensorflow.python.framework.ops.EagerTensor'>

batch_of_features has shape: (32, 10)

batch_of_labels has shape: (32,)

First element in batch_of_features is equal to first 10 elements in the series: True

batch_of_labels is equal to the first 32 values after the window_lenght of 10): True

when i test it : All tests passed!

Not closing a bracket is a syntax error in python. Please fix it when invoking model.evaluate

am sorry for the brackets , and the code you gave me worked and i got ‘All tests passed!‘ but still Failed test case: Got a wrong value for the MSE loss. Expected: MSE<30, but got: 32.009769439697266.

also on Check the parameter count against a reference solution

predictions have shape: (32, 1)

Expected output:

predictions have shape: (NUM_BATCHES, 1)

Where NUM_BATCHES is the number of batches you have set to your dataset.

Regd. parameter count, as specified in the markdown, the staff don’t want you to build a model that’ll exceed grader resources and hence the check.

To satisfy error thresholds, try different model architectures and optimizers (eg. adam)

thank you so much mister , your advice , and your help , pull me out

You’re welcome.