diff --git a/examples/timeseries/img/timeseries_weather_forecasting/timeseries_weather_forecasting_22_0.png b/examples/timeseries/img/timeseries_weather_forecasting/timeseries_weather_forecasting_22_0.png
index 371ff0f9ce..f1779e47c9 100644
Binary files a/examples/timeseries/img/timeseries_weather_forecasting/timeseries_weather_forecasting_22_0.png and b/examples/timeseries/img/timeseries_weather_forecasting/timeseries_weather_forecasting_22_0.png differ
diff --git a/examples/timeseries/img/timeseries_weather_forecasting/timeseries_weather_forecasting_24_12.png b/examples/timeseries/img/timeseries_weather_forecasting/timeseries_weather_forecasting_24_12.png
new file mode 100644
index 0000000000..05c3e7061c
Binary files /dev/null and b/examples/timeseries/img/timeseries_weather_forecasting/timeseries_weather_forecasting_24_12.png differ
diff --git a/examples/timeseries/img/timeseries_weather_forecasting/timeseries_weather_forecasting_24_13.png b/examples/timeseries/img/timeseries_weather_forecasting/timeseries_weather_forecasting_24_13.png
new file mode 100644
index 0000000000..e698324ebb
Binary files /dev/null and b/examples/timeseries/img/timeseries_weather_forecasting/timeseries_weather_forecasting_24_13.png differ
diff --git a/examples/timeseries/img/timeseries_weather_forecasting/timeseries_weather_forecasting_24_15.png b/examples/timeseries/img/timeseries_weather_forecasting/timeseries_weather_forecasting_24_15.png
new file mode 100644
index 0000000000..4a1af53602
Binary files /dev/null and b/examples/timeseries/img/timeseries_weather_forecasting/timeseries_weather_forecasting_24_15.png differ
diff --git a/examples/timeseries/img/timeseries_weather_forecasting/timeseries_weather_forecasting_24_16.png b/examples/timeseries/img/timeseries_weather_forecasting/timeseries_weather_forecasting_24_16.png
new file mode 100644
index 0000000000..681dc8cda3
Binary files /dev/null and b/examples/timeseries/img/timeseries_weather_forecasting/timeseries_weather_forecasting_24_16.png differ
diff --git a/examples/timeseries/img/timeseries_weather_forecasting/timeseries_weather_forecasting_24_2.png b/examples/timeseries/img/timeseries_weather_forecasting/timeseries_weather_forecasting_24_2.png
new file mode 100644
index 0000000000..b06acc2683
Binary files /dev/null and b/examples/timeseries/img/timeseries_weather_forecasting/timeseries_weather_forecasting_24_2.png differ
diff --git a/examples/timeseries/img/timeseries_weather_forecasting/timeseries_weather_forecasting_24_5.png b/examples/timeseries/img/timeseries_weather_forecasting/timeseries_weather_forecasting_24_5.png
index b6ed60cd3d..eb86303716 100644
Binary files a/examples/timeseries/img/timeseries_weather_forecasting/timeseries_weather_forecasting_24_5.png and b/examples/timeseries/img/timeseries_weather_forecasting/timeseries_weather_forecasting_24_5.png differ
diff --git a/examples/timeseries/img/timeseries_weather_forecasting/timeseries_weather_forecasting_24_6.png b/examples/timeseries/img/timeseries_weather_forecasting/timeseries_weather_forecasting_24_6.png
new file mode 100644
index 0000000000..fc75c215de
Binary files /dev/null and b/examples/timeseries/img/timeseries_weather_forecasting/timeseries_weather_forecasting_24_6.png differ
diff --git a/examples/timeseries/img/timeseries_weather_forecasting/timeseries_weather_forecasting_24_8.png b/examples/timeseries/img/timeseries_weather_forecasting/timeseries_weather_forecasting_24_8.png
new file mode 100644
index 0000000000..e9d5f53ff2
Binary files /dev/null and b/examples/timeseries/img/timeseries_weather_forecasting/timeseries_weather_forecasting_24_8.png differ
diff --git a/examples/timeseries/img/timeseries_weather_forecasting/timeseries_weather_forecasting_24_9.png b/examples/timeseries/img/timeseries_weather_forecasting/timeseries_weather_forecasting_24_9.png
index 87a397e249..c22b95239f 100644
Binary files a/examples/timeseries/img/timeseries_weather_forecasting/timeseries_weather_forecasting_24_9.png and b/examples/timeseries/img/timeseries_weather_forecasting/timeseries_weather_forecasting_24_9.png differ
diff --git a/examples/timeseries/img/timeseries_weather_forecasting/timeseries_weather_forecasting_6_0.png b/examples/timeseries/img/timeseries_weather_forecasting/timeseries_weather_forecasting_6_0.png
index ebe040d9ff..dbb33cdd4b 100644
Binary files a/examples/timeseries/img/timeseries_weather_forecasting/timeseries_weather_forecasting_6_0.png and b/examples/timeseries/img/timeseries_weather_forecasting/timeseries_weather_forecasting_6_0.png differ
diff --git a/examples/timeseries/ipynb/timeseries_traffic_forecasting.ipynb b/examples/timeseries/ipynb/timeseries_traffic_forecasting.ipynb
index dc5b333332..ea740fe141 100644
--- a/examples/timeseries/ipynb/timeseries_traffic_forecasting.ipynb
+++ b/examples/timeseries/ipynb/timeseries_traffic_forecasting.ipynb
@@ -10,7 +10,7 @@
"\n",
"**Author:** [Arash Khodadadi](https://www.linkedin.com/in/arash-khodadadi-08a02490/)
\n",
"**Date created:** 2021/12/28
\n",
- "**Last modified:** 2023/11/22
\n",
+ "**Last modified:** 2026/02/01
\n",
"**Description:** This example demonstrates how to do timeseries forecasting over graphs."
]
},
@@ -132,9 +132,13 @@
"outputs": [],
"source": [
"url = \"https://github.com/VeritasYin/STGCN_IJCAI-18/raw/master/dataset/PeMSD7_Full.zip\"\n",
- "data_dir = keras.utils.get_file(origin=url, extract=True, archive_format=\"zip\")\n",
- "data_dir = data_dir.rstrip(\"PeMSD7_Full.zip\")\n",
+ "# 1. Download and extract normally\n",
+ "zip_path = keras.utils.get_file(origin=url, extract=True, archive_format=\"zip\")\n",
"\n",
+ "# 2. FIX: Use os.path.dirname to safely get the folder where it was extracted\n",
+ "data_dir = os.path.dirname(zip_path)\n",
+ "\n",
+ "# 3. Construct the paths to the inner files safely\n",
"route_distances = pd.read_csv(\n",
" os.path.join(data_dir, \"PeMSD7_W_228.csv\"), header=None\n",
").to_numpy()\n",
@@ -798,7 +802,7 @@
"source": [
"in_feat = 1\n",
"batch_size = 64\n",
- "epochs = 20\n",
+ "epochs = 1\n",
"input_sequence_length = 12\n",
"forecast_horizon = 3\n",
"multi_horizon = False\n",
diff --git a/examples/timeseries/ipynb/timeseries_weather_forecasting.ipynb b/examples/timeseries/ipynb/timeseries_weather_forecasting.ipynb
index 08238ad8a2..51a7eee220 100644
--- a/examples/timeseries/ipynb/timeseries_weather_forecasting.ipynb
+++ b/examples/timeseries/ipynb/timeseries_weather_forecasting.ipynb
@@ -10,7 +10,7 @@
"\n",
"**Authors:** [Prabhanshu Attri](https://prabhanshu.com/github), [Yashika Sharma](https://github.com/yashika51), [Kristi Takach](https://github.com/ktakattack), [Falak Shah](https://github.com/falaktheoptimist)
\n",
"**Date created:** 2020/06/23
\n",
- "**Last modified:** 2023/11/22
\n",
+ "**Last modified:** 2026/02/01
\n",
"**Description:** This notebook demonstrates how to do timeseries forecasting using a LSTM model."
]
},
@@ -31,6 +31,7 @@
},
"outputs": [],
"source": [
+ "import os\n",
"import pandas as pd\n",
"import matplotlib.pyplot as plt\n",
"import keras"
@@ -84,13 +85,18 @@
},
"outputs": [],
"source": [
+ "\n",
"from zipfile import ZipFile\n",
"\n",
"uri = \"https://storage.googleapis.com/tensorflow/tf-keras-datasets/jena_climate_2009_2016.csv.zip\"\n",
"zip_path = keras.utils.get_file(origin=uri, fname=\"jena_climate_2009_2016.csv.zip\")\n",
"zip_file = ZipFile(zip_path)\n",
- "zip_file.extractall()\n",
- "csv_path = \"jena_climate_2009_2016.csv\"\n",
+ "\n",
+ "# FIX: Extract to the cache directory, not the current working directory\n",
+ "zip_file.extractall(path=os.path.dirname(zip_path))\n",
+ "\n",
+ "# FIX: Construct the absolute path safely (works on Windows/Linux/Mac)\n",
+ "csv_path = os.path.join(os.path.dirname(zip_path), \"jena_climate_2009_2016.csv\")\n",
"\n",
"df = pd.read_csv(csv_path)"
]
@@ -236,7 +242,7 @@
"future = 72\n",
"learning_rate = 0.001\n",
"batch_size = 256\n",
- "epochs = 10\n",
+ "epochs = 1\n",
"\n",
"\n",
"def normalize(data, train_split):\n",
diff --git a/examples/timeseries/md/timeseries_weather_forecasting.md b/examples/timeseries/md/timeseries_weather_forecasting.md
index ac5a5bead0..769becdfbf 100644
--- a/examples/timeseries/md/timeseries_weather_forecasting.md
+++ b/examples/timeseries/md/timeseries_weather_forecasting.md
@@ -2,7 +2,7 @@
**Authors:** [Prabhanshu Attri](https://prabhanshu.com/github), [Yashika Sharma](https://github.com/yashika51), [Kristi Takach](https://github.com/ktakattack), [Falak Shah](https://github.com/falaktheoptimist)
**Date created:** 2020/06/23
-**Last modified:** 2023/11/22
+**Last modified:** 2026/02/01
**Description:** This notebook demonstrates how to do timeseries forecasting using a LSTM model.
@@ -15,11 +15,24 @@
```python
+import os
import pandas as pd
import matplotlib.pyplot as plt
import keras
```
+
Model: "functional_1" +Model: "functional"-┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┓ -┃ Layer (type) ┃ Output Shape ┃ Param # ┃ -┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━┩ -│ input_layer (InputLayer) │ (None, 120, 7) │ 0 │ -├─────────────────────────────────┼───────────────────────────┼────────────┤ -│ lstm (LSTM) │ (None, 32) │ 5,120 │ -├─────────────────────────────────┼───────────────────────────┼────────────┤ -│ dense (Dense) │ (None, 1) │ 33 │ -└─────────────────────────────────┴───────────────────────────┴────────────┘ +┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓ +┃ Layer (type) ┃ Output Shape ┃ Param # ┃ +┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩ +│ input_layer (InputLayer) │ (None, 120, 7) │ 0 │ +├─────────────────────────────────┼────────────────────────┼───────────────┤ +│ lstm (LSTM) │ (None, 32) │ 5,120 │ +├─────────────────────────────────┼────────────────────────┼───────────────┤ +│ dense (Dense) │ (None, 1) │ 33 │ +└─────────────────────────────────┴────────────────────────┴───────────────┘@@ -382,51 +395,19 @@ history = model.fit( ) ``` +``` -Epoch 1/10 - 1172/1172 ━━━━━━━━━━━━━━━━━━━━ 0s 70ms/step - loss: 0.3008 -Epoch 1: val_loss improved from inf to 0.15039, saving model to model_checkpoint.weights.h5 - 1172/1172 ━━━━━━━━━━━━━━━━━━━━ 104s 88ms/step - loss: 0.3007 - val_loss: 0.1504 -Epoch 2/10 - 1171/1172 ━━━━━━━━━━━━━━━━━━━[37m━ 0s 66ms/step - loss: 0.1397 -Epoch 2: val_loss improved from 0.15039 to 0.14231, saving model to model_checkpoint.weights.h5 - 1172/1172 ━━━━━━━━━━━━━━━━━━━━ 97s 83ms/step - loss: 0.1396 - val_loss: 0.1423 -Epoch 3/10 - 1171/1172 ━━━━━━━━━━━━━━━━━━━[37m━ 0s 69ms/step - loss: 0.1242 -Epoch 3: val_loss did not improve from 0.14231 - 1172/1172 ━━━━━━━━━━━━━━━━━━━━ 101s 86ms/step - loss: 0.1242 - val_loss: 0.1513 -Epoch 4/10 - 1172/1172 ━━━━━━━━━━━━━━━━━━━━ 0s 68ms/step - loss: 0.1182 -Epoch 4: val_loss did not improve from 0.14231 - 1172/1172 ━━━━━━━━━━━━━━━━━━━━ 102s 87ms/step - loss: 0.1182 - val_loss: 0.1503 -Epoch 5/10 - 1171/1172 ━━━━━━━━━━━━━━━━━━━[37m━ 0s 67ms/step - loss: 0.1160 -Epoch 5: val_loss did not improve from 0.14231 - 1172/1172 ━━━━━━━━━━━━━━━━━━━━ 100s 85ms/step - loss: 0.1160 - val_loss: 0.1500 -Epoch 6/10 - 1171/1172 ━━━━━━━━━━━━━━━━━━━[37m━ 0s 69ms/step - loss: 0.1130 -Epoch 6: val_loss did not improve from 0.14231 - 1172/1172 ━━━━━━━━━━━━━━━━━━━━ 100s 86ms/step - loss: 0.1130 - val_loss: 0.1469 -Epoch 7/10 - 1172/1172 ━━━━━━━━━━━━━━━━━━━━ 0s 70ms/step - loss: 0.1106 -Epoch 7: val_loss improved from 0.14231 to 0.13916, saving model to model_checkpoint.weights.h5 - 1172/1172 ━━━━━━━━━━━━━━━━━━━━ 104s 89ms/step - loss: 0.1106 - val_loss: 0.1392 -Epoch 8/10 - 1171/1172 ━━━━━━━━━━━━━━━━━━━[37m━ 0s 66ms/step - loss: 0.1097 -Epoch 8: val_loss improved from 0.13916 to 0.13257, saving model to model_checkpoint.weights.h5 - 1172/1172 ━━━━━━━━━━━━━━━━━━━━ 98s 84ms/step - loss: 0.1097 - val_loss: 0.1326 -Epoch 9/10 - 1171/1172 ━━━━━━━━━━━━━━━━━━━[37m━ 0s 68ms/step - loss: 0.1075 -Epoch 9: val_loss improved from 0.13257 to 0.13057, saving model to model_checkpoint.weights.h5 - 1172/1172 ━━━━━━━━━━━━━━━━━━━━ 100s 85ms/step - loss: 0.1075 - val_loss: 0.1306 -Epoch 10/10 - 1172/1172 ━━━━━━━━━━━━━━━━━━━━ 0s 66ms/step - loss: 0.1065 -Epoch 10: val_loss improved from 0.13057 to 0.12671, saving model to model_checkpoint.weights.h5 - 1172/1172 ━━━━━━━━━━━━━━━━━━━━ 98s 84ms/step - loss: 0.1065 - val_loss: 0.1267 +1172/1172 ━━━━━━━━━━━━━━━━━━━━ 0s 62ms/step - loss: 0.3293 + +Epoch 1: val_loss improved from None to 0.15638, saving model to model_checkpoint.weights.h5 + +Epoch 1: finished saving model to model_checkpoint.weights.h5 +1172/1172 ━━━━━━━━━━━━━━━━━━━━ 92s 78ms/step - loss: 0.1987 - val_loss: 0.1564 ```+ We can visualize the loss with the function below. After one point, the loss stops decreasing. @@ -495,57 +476,57 @@ for x, y in dataset_val.take(5): ) ``` +``` - 8/8 ━━━━━━━━━━━━━━━━━━━━ 0s 4ms/step - +8/8 ━━━━━━━━━━━━━━━━━━━━ 0s 6ms/step ```- - + + +``` - 8/8 ━━━━━━━━━━━━━━━━━━━━ 0s 4ms/step - +8/8 ━━━━━━━━━━━━━━━━━━━━ 0s 9ms/step ```- - + + +``` - 8/8 ━━━━━━━━━━━━━━━━━━━━ 0s 5ms/step - +8/8 ━━━━━━━━━━━━━━━━━━━━ 0s 7ms/step ```- - + + +``` - 8/8 ━━━━━━━━━━━━━━━━━━━━ 0s 5ms/step - +8/8 ━━━━━━━━━━━━━━━━━━━━ 0s 9ms/step ```- - + + +``` - 8/8 ━━━━━━━━━━━━━━━━━━━━ 0s 4ms/step - +8/8 ━━━━━━━━━━━━━━━━━━━━ 0s 6ms/step ```- - + + diff --git a/examples/timeseries/timeseries_traffic_forecasting.py b/examples/timeseries/timeseries_traffic_forecasting.py index ea66ee2131..e142ec8b06 100644 --- a/examples/timeseries/timeseries_traffic_forecasting.py +++ b/examples/timeseries/timeseries_traffic_forecasting.py @@ -2,7 +2,7 @@ Title: Traffic forecasting using graph neural networks and LSTM Author: [Arash Khodadadi](https://www.linkedin.com/in/arash-khodadadi-08a02490/) Date created: 2021/12/28 -Last modified: 2023/11/22 +Last modified: 2026/02/01 Description: This example demonstrates how to do timeseries forecasting over graphs. Accelerator: GPU """ @@ -83,9 +83,13 @@ """ url = "https://github.com/VeritasYin/STGCN_IJCAI-18/raw/master/dataset/PeMSD7_Full.zip" -data_dir = keras.utils.get_file(origin=url, extract=True, archive_format="zip") -data_dir = data_dir.rstrip("PeMSD7_Full.zip") +# 1. Download and extract normally +zip_path = keras.utils.get_file(origin=url, extract=True, archive_format="zip") +# 2. FIX: Use os.path.dirname to safely get the folder where it was extracted +data_dir = os.path.dirname(zip_path) + +# 3. Construct the paths to the inner files safely route_distances = pd.read_csv( os.path.join(data_dir, "PeMSD7_W_228.csv"), header=None ).to_numpy() diff --git a/examples/timeseries/timeseries_weather_forecasting.py b/examples/timeseries/timeseries_weather_forecasting.py index 0b30771948..ce480102d1 100644 --- a/examples/timeseries/timeseries_weather_forecasting.py +++ b/examples/timeseries/timeseries_weather_forecasting.py @@ -2,7 +2,7 @@ Title: Timeseries forecasting for weather prediction Authors: [Prabhanshu Attri](https://prabhanshu.com/github), [Yashika Sharma](https://github.com/yashika51), [Kristi Takach](https://github.com/ktakattack), [Falak Shah](https://github.com/falaktheoptimist) Date created: 2020/06/23 -Last modified: 2023/11/22 +Last modified: 2026/02/01 Description: This notebook demonstrates how to do timeseries forecasting using a LSTM model. Accelerator: GPU """ @@ -10,7 +10,7 @@ """ ## Setup """ - +import os import pandas as pd import matplotlib.pyplot as plt import keras @@ -50,13 +50,18 @@ 15 |wd (deg) |152.3 |Wind direction in degrees """ + from zipfile import ZipFile uri = "https://storage.googleapis.com/tensorflow/tf-keras-datasets/jena_climate_2009_2016.csv.zip" zip_path = keras.utils.get_file(origin=uri, fname="jena_climate_2009_2016.csv.zip") zip_file = ZipFile(zip_path) -zip_file.extractall() -csv_path = "jena_climate_2009_2016.csv" + +# FIX: Extract to the cache directory, not the current working directory +zip_file.extractall(path=os.path.dirname(zip_path)) + +# FIX: Construct the absolute path safely (works on Windows/Linux/Mac) +csv_path = os.path.join(os.path.dirname(zip_path), "jena_climate_2009_2016.csv") df = pd.read_csv(csv_path)