# Course 4 Week 2: Predicting time series

**URL:** <https://community.deeplearning.ai/t/course-4-week-2-predicting-time-series/880472>\
**Category:** Sequences, Time Series and Prediction\
**Tags:** week-module-2\
**Created:** [September 30, 2025, 8:54am UTC](https://community.deeplearning.ai/t/course-4-week-2-predicting-time-series/880472 "2025-09-30T08:54:17Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![OsamaAT](https://avatars.discourse-cdn.com/v4/letter/o/3be4f8/32.png) [@OsamaAT](https://community.deeplearning.ai/u/OsamaAT)\
**Post date:** [September 30, 2025, 8:54am UTC](https://community.deeplearning.ai/t/course-4-week-2-predicting-time-series/880472/1 "2025-09-30T08:54:17Z")

</div>

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`:

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

```

When I test with:

```auto
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:

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

```

I also checked shapes:

```auto
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 🙏

---

<div class="post-metadata">

**Author:** ![balaji.ambresh](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/balaji.ambresh/32/128697_2.png) [@balaji.ambresh](https://community.deeplearning.ai/u/balaji.ambresh)\
**Post date:** [September 30, 2025, 5:40pm UTC](https://community.deeplearning.ai/t/course-4-week-2-predicting-time-series/880472/2 "2025-09-30T17:40:00Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Deepti\_Prasad](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/deepti_prasad/32/165831_2.png) [@Deepti\_Prasad](https://community.deeplearning.ai/u/Deepti_Prasad)\
**Post date:** [September 30, 2025, 7:17pm UTC](https://community.deeplearning.ai/t/course-4-week-2-predicting-time-series/880472/3 "2025-09-30T19:17:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![OsamaAT](https://avatars.discourse-cdn.com/v4/letter/o/3be4f8/32.png) [@OsamaAT](https://community.deeplearning.ai/u/OsamaAT)\
**Post date:** [October 1, 2025, 10:10am UTC](https://community.deeplearning.ai/t/course-4-week-2-predicting-time-series/880472/4 "2025-10-01T10:10:51Z")

</div>

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

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

```

I got the error:

```auto
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.

---

<div class="post-metadata">

**Author:** ![OsamaAT](https://avatars.discourse-cdn.com/v4/letter/o/3be4f8/32.png) [@OsamaAT](https://community.deeplearning.ai/u/OsamaAT)\
**Post date:** [October 1, 2025, 10:12am UTC](https://community.deeplearning.ai/t/course-4-week-2-predicting-time-series/880472/5 "2025-10-01T10:12:47Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![balaji.ambresh](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/balaji.ambresh/32/128697_2.png) [@balaji.ambresh](https://community.deeplearning.ai/u/balaji.ambresh)\
**Post date:** [October 1, 2025, 11:17am UTC](https://community.deeplearning.ai/t/course-4-week-2-predicting-time-series/880472/6 "2025-10-01T11:17:35Z")

</div>

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

Try this:

```python
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?

---

<div class="post-metadata">

**Author:** ![OsamaAT](https://avatars.discourse-cdn.com/v4/letter/o/3be4f8/32.png) [@OsamaAT](https://community.deeplearning.ai/u/OsamaAT)\
**Post date:** [October 1, 2025, 11:53am UTC](https://community.deeplearning.ai/t/course-4-week-2-predicting-time-series/880472/7 "2025-10-01T11:53:27Z")

</div>

```auto

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

```

The output of window\_dataset is like the expected output :

```auto
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!

---

<div class="post-metadata">

**Author:** ![balaji.ambresh](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/balaji.ambresh/32/128697_2.png) [@balaji.ambresh](https://community.deeplearning.ai/u/balaji.ambresh)\
**Post date:** [October 1, 2025, 11:55am UTC](https://community.deeplearning.ai/t/course-4-week-2-predicting-time-series/880472/8 "2025-10-01T11:55:15Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![OsamaAT](https://avatars.discourse-cdn.com/v4/letter/o/3be4f8/32.png) [@OsamaAT](https://community.deeplearning.ai/u/OsamaAT)\
**Post date:** [October 1, 2025, 1:49pm UTC](https://community.deeplearning.ai/t/course-4-week-2-predicting-time-series/880472/9 "2025-10-01T13:49:44Z")

</div>

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**

```auto
predictions have shape: (32, 1)

```

**Expected output:**

```auto
predictions have shape: (NUM_BATCHES, 1)

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

```

---

<div class="post-metadata">

**Author:** ![balaji.ambresh](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/balaji.ambresh/32/128697_2.png) [@balaji.ambresh](https://community.deeplearning.ai/u/balaji.ambresh)\
**Post date:** [October 1, 2025, 4:56pm UTC](https://community.deeplearning.ai/t/course-4-week-2-predicting-time-series/880472/11 "2025-10-01T16:56:22Z")

</div>

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`)

---

<div class="post-metadata">

**Author:** ![OsamaAT](https://avatars.discourse-cdn.com/v4/letter/o/3be4f8/32.png) [@OsamaAT](https://community.deeplearning.ai/u/OsamaAT)\
**Post date:** [October 2, 2025, 9:17am UTC](https://community.deeplearning.ai/t/course-4-week-2-predicting-time-series/880472/12 "2025-10-02T09:17:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![balaji.ambresh](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/balaji.ambresh/32/128697_2.png) [@balaji.ambresh](https://community.deeplearning.ai/u/balaji.ambresh)\
**Post date:** [October 2, 2025, 10:02am UTC](https://community.deeplearning.ai/t/course-4-week-2-predicting-time-series/880472/13 "2025-10-02T10:02:16Z")

</div>

You’re welcome.
