[MODELS] Cleanup Jupyter Notebooks.
[thoth.git] / models / failure_prediction / jnotebooks / LSTM_correlation.ipynb
1 {
2  "cells": [
3   {
4    "cell_type": "markdown",
5    "metadata": {
6     "id": "RW6MfrDdMIP7"
7    },
8    "source": [
9     "Contributors: Rohit Singh Rathaur, Girish L.\n",
10     "\n",
11     "Copyright 2021 [Rohit Singh Rathaur, BIT Mesra and Girish L., CIT GUBBI, Karnataka]\n",
12     "\n",
13     "Licensed under the Apache License, Version 2.0 (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at\n",
14     "\n",
15     "http://www.apache.org/licenses/LICENSE-2.0\n",
16     "Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License."
17    ]
18   },
19   {
20    "cell_type": "code",
21    "execution_count": null,
22    "metadata": {
23     "colab": {
24      "base_uri": "https://localhost:8080/"
25     },
26     "id": "YQ6lT1e2hrx4",
27     "outputId": "cb34bd5a-8e52-43cc-90d1-954431091e6b"
28    },
29    "outputs": [],
30    "source": [
31     "from google.colab import drive\n",
32     "drive.mount('/gdrive')"
33    ]
34   },
35   {
36    "cell_type": "markdown",
37    "metadata": {
38     "id": "V4G3MxsJMN4m"
39    },
40    "source": [
41     "We are importing the libraries:\n",
42     "\n",
43     "- TensorFlow: to process and train the model\n",
44     "- Matplotlib: to plot the training anf loss curves\n",
45     "- Pandas: used for data analysis and it allows us to import data from various formats\n",
46     "- Numpy: For array computing"
47    ]
48   },
49   {
50    "cell_type": "code",
51    "execution_count": null,
52    "metadata": {
53     "id": "tLhroy5BnMnC"
54    },
55    "outputs": [],
56    "source": [
57     "# Importing libraries\n",
58     "import tensorflow as tf\n",
59     "import matplotlib.pyplot as plt\n",
60     "import matplotlib as mpl\n",
61     "import pandas as pd\n",
62     "import numpy as np\n",
63     "import os"
64    ]
65   },
66   {
67    "cell_type": "markdown",
68    "metadata": {
69     "id": "W46t-S6TMZVG"
70    },
71    "source": [
72     "We are reading the CSV file using `read_csv` function and storing it in a DataFrame named `df_Ellis`"
73    ]
74   },
75   {
76    "cell_type": "code",
77    "execution_count": null,
78    "metadata": {
79     "colab": {
80      "base_uri": "https://localhost:8080/",
81      "height": 521
82     },
83     "id": "2-UpMVsSnfCI",
84     "outputId": "94530f09-ebe1-4361-9b23-e21ec5f0f649"
85    },
86    "outputs": [],
87    "source": [
88     "df_Ellis  = pd.read_csv(\"/gdrive/MyDrive/LFN Anuket/Analysis/data/Final/Ellis_FinalTwoConditionwithOR.csv\")\n",
89     "df_Ellis"
90    ]
91   },
92   {
93    "cell_type": "code",
94    "execution_count": null,
95    "metadata": {
96     "colab": {
97      "base_uri": "https://localhost:8080/",
98      "height": 293
99     },
100     "id": "92xBt43BnjAo",
101     "outputId": "727ad3d1-e00a-4d6e-9ce8-6859b01fa6ce"
102    },
103    "outputs": [],
104    "source": [
105     "df_Ellis.plot()"
106    ]
107   },
108   {
109    "cell_type": "code",
110    "execution_count": null,
111    "metadata": {
112     "colab": {
113      "base_uri": "https://localhost:8080/",
114      "height": 879
115     },
116     "id": "RSo-aa-SIoBR",
117     "outputId": "c4a79b59-30eb-41ba-9d34-2c7cad07d9f2"
118    },
119    "outputs": [],
120    "source": [
121     "# we show here the hist\n",
122     "df_Ellis.hist(bins=100,figsize=(20,15))\n",
123     "#save_fig(\"attribute_histogram_plots\")\n",
124     "plt.show()"
125    ]
126   },
127   {
128    "cell_type": "code",
129    "execution_count": null,
130    "metadata": {
131     "colab": {
132      "base_uri": "https://localhost:8080/",
133      "height": 634
134     },
135     "id": "gggaMJ_2LtFs",
136     "outputId": "f96a17fc-a509-4c29-e57f-1dfda73d8df6"
137    },
138    "outputs": [],
139    "source": [
140     "cpu_system_perc = df_Ellis[['ellis-cpu.system_perc']] \n",
141     "cpu_system_perc.rolling(12).mean().plot(figsize=(20,10), linewidth=5, fontsize=20) \n",
142     "plt.xlabel('Timestamp', fontsize=30);"
143    ]
144   },
145   {
146    "cell_type": "code",
147    "execution_count": null,
148    "metadata": {
149     "colab": {
150      "base_uri": "https://localhost:8080/",
151      "height": 634
152     },
153     "id": "R_ctvXcQL1Xf",
154     "outputId": "4a3a36e3-c071-4353-cd86-0ab6b1afba0e"
155    },
156    "outputs": [],
157    "source": [
158     "load_avg_1_min = df_Ellis[['ellis-load.avg_1_min']] \n",
159     "load_avg_1_min.rolling(12).mean().plot(figsize=(20,10), linewidth=5, fontsize=20) \n",
160     "plt.xlabel('Timestamp', fontsize=30);"
161    ]
162   },
163   {
164    "cell_type": "code",
165    "execution_count": null,
166    "metadata": {
167     "colab": {
168      "base_uri": "https://localhost:8080/",
169      "height": 634
170     },
171     "id": "Gkd5ecCmL6Bw",
172     "outputId": "385a467a-5cb2-49e9-ba49-dd68c7cfb6c6"
173    },
174    "outputs": [],
175    "source": [
176     "cpu_wait_perc = df_Ellis[['ellis-cpu.wait_perc']] \n",
177     "cpu_wait_perc.rolling(12).mean().plot(figsize=(20,10), linewidth=5, fontsize=20) \n",
178     "plt.xlabel('Year', fontsize=30);"
179    ]
180   },
181   {
182    "cell_type": "code",
183    "execution_count": null,
184    "metadata": {
185     "colab": {
186      "base_uri": "https://localhost:8080/",
187      "height": 624
188     },
189     "id": "EycZrQU0MBSX",
190     "outputId": "73cb3b63-1038-48d3-ff11-1a2dda4941df"
191    },
192    "outputs": [],
193    "source": [
194     "df_dg = pd.concat([cpu_system_perc.rolling(12).mean(), load_avg_1_min.rolling(12).mean(),cpu_wait_perc.rolling(12).mean()], axis=1) \n",
195     "df_dg.plot(figsize=(20,10), linewidth=5, fontsize=20) \n",
196     "plt.xlabel('Year', fontsize=20); "
197    ]
198   },
199   {
200    "cell_type": "code",
201    "execution_count": null,
202    "metadata": {
203     "colab": {
204      "base_uri": "https://localhost:8080/",
205      "height": 710
206     },
207     "id": "Pi8UMMitMa3Q",
208     "outputId": "548bd638-42a5-4cc4-c073-01f07ad9a4cd"
209    },
210    "outputs": [],
211    "source": [
212     "# we establish the corrmartrice\n",
213     "import seaborn as sns\n",
214     "color = sns.color_palette()\n",
215     "sns.set_style('darkgrid')\n",
216     "\n",
217     "correaltionMatrice = df_Ellis.corr()\n",
218     "f, ax = plt.subplots(figsize=(20, 10))\n",
219     "sns.heatmap(correaltionMatrice, cbar=True, vmin=0, vmax=1, square=True, annot=True);\n",
220     "plt.show()"
221    ]
222   },
223   {
224    "cell_type": "code",
225    "execution_count": null,
226    "metadata": {
227     "colab": {
228      "base_uri": "https://localhost:8080/"
229     },
230     "id": "rkYwyKtXMvpy",
231     "outputId": "05a92d00-674b-4e12-c9d4-4a70b2d19768"
232    },
233    "outputs": [],
234    "source": [
235     "df_Ellis.corrwith(df_Ellis['ellis-load.avg_1_min'])"
236    ]
237   },
238   {
239    "cell_type": "code",
240    "execution_count": null,
241    "metadata": {
242     "colab": {
243      "base_uri": "https://localhost:8080/",
244      "height": 235
245     },
246     "id": "5oQK-ddinvCM",
247     "outputId": "fd00e983-d38e-4d4a-f1e1-23ab6525ecc8"
248    },
249    "outputs": [],
250    "source": [
251     "## ## using multivariate feature \n",
252     "\n",
253     "features_3 = ['ellis-cpu.wait_perc', 'ellis-load.avg_1_min', 'ellis-net.in_bytes_sec', 'Label']\n",
254     "\n",
255     "features = df_Ellis[features_3]\n",
256     "features.index = df_Ellis['Timestamp']\n",
257     "features.head()"
258    ]
259   },
260   {
261    "cell_type": "code",
262    "execution_count": null,
263    "metadata": {
264     "colab": {
265      "base_uri": "https://localhost:8080/",
266      "height": 386
267     },
268     "id": "qbqn755fo81g",
269     "outputId": "c9204a3a-f6a7-44de-a499-32280bf3e02b"
270    },
271    "outputs": [],
272    "source": [
273     "features.plot(subplots=True)"
274    ]
275   },
276   {
277    "cell_type": "code",
278    "execution_count": null,
279    "metadata": {
280     "id": "jJQD1x9psWCH"
281    },
282    "outputs": [],
283    "source": [
284     "features = features.values"
285    ]
286   },
287   {
288    "cell_type": "code",
289    "execution_count": null,
290    "metadata": {
291     "colab": {
292      "base_uri": "https://localhost:8080/"
293     },
294     "id": "xf8WCiykpUzN",
295     "outputId": "ef830bbd-5c4e-4dc7-c1ea-3d112d7d809e"
296    },
297    "outputs": [],
298    "source": [
299     "### standardize data\n",
300     "train_split = 141600\n",
301     "tf.random.set_seed(13)\n",
302     "\n",
303     "### standardize data\n",
304     "features_mean = features[:train_split].mean()\n",
305     "features_std = features[:train_split].std()\n",
306     "features  = (features - features_mean)/ features_std\n",
307     "\n",
308     "print(type(features))\n",
309     "print(features.shape)\n"
310    ]
311   },
312   {
313    "cell_type": "code",
314    "execution_count": null,
315    "metadata": {
316     "id": "1a0hNDmppnLB"
317    },
318    "outputs": [],
319    "source": [
320     "### create mutlivariate data\n",
321     "\n",
322     "def mutlivariate_data(features , target , start_idx , end_idx , history_size , target_size,\n",
323     "                      step ,  single_step = False):\n",
324     "  data = []\n",
325     "  labels = []\n",
326     "  start_idx = start_idx + history_size\n",
327     "  if end_idx is None:\n",
328     "    end_idx = len(features)- target_size\n",
329     "  for i in range(start_idx , end_idx ):\n",
330     "    idxs = range(i-history_size, i, step) ### using step\n",
331     "    data.append(features[idxs])\n",
332     "    if single_step:\n",
333     "      labels.append(target[i+target_size])\n",
334     "    else:\n",
335     "      labels.append(target[i:i+target_size])\n",
336     "\n",
337     "  return np.array(data) , np.array(labels)"
338    ]
339   },
340   {
341    "cell_type": "code",
342    "execution_count": null,
343    "metadata": {
344     "colab": {
345      "base_uri": "https://localhost:8080/"
346     },
347     "id": "Z0CivgkitfgE",
348     "outputId": "8057191e-6d36-429f-d649-12689677409a"
349    },
350    "outputs": [],
351    "source": [
352     "### generate multivariate data\n",
353     "\n",
354     "history = 720\n",
355     "future_target = 72\n",
356     "STEP = 6\n",
357     "\n",
358     "x_train_ss , y_train_ss = mutlivariate_data(features , features[:, 1], 0, train_split, history,\n",
359     "                                            future_target, STEP , single_step = True)\n",
360     "\n",
361     "x_val_ss , y_val_ss = mutlivariate_data(features , features[:,1] , train_split , None , history ,\n",
362     "                                        future_target, STEP, single_step = True)\n",
363     "\n",
364     "print(x_train_ss.shape , y_train_ss.shape)\n",
365     "print(x_val_ss.shape , y_val_ss.shape)"
366    ]
367   },
368   {
369    "cell_type": "code",
370    "execution_count": null,
371    "metadata": {
372     "colab": {
373      "base_uri": "https://localhost:8080/"
374     },
375     "id": "VBdr2epGu3aq",
376     "outputId": "42891ad8-9f74-4c75-a750-776d3d6b8ceb"
377    },
378    "outputs": [],
379    "source": [
380     "## tensorflow dataset\n",
381     "batch_size = 256\n",
382     "buffer_size = 10000\n",
383     "\n",
384     "train_ss = tf.data.Dataset.from_tensor_slices((x_train_ss, y_train_ss))\n",
385     "train_ss = train_ss.cache().shuffle(buffer_size).batch(batch_size).repeat()\n",
386     "\n",
387     "val_ss = tf.data.Dataset.from_tensor_slices((x_val_ss, y_val_ss))\n",
388     "val_ss = val_ss.cache().shuffle(buffer_size).batch(batch_size).repeat()\n",
389     "\n",
390     "print(train_ss)\n",
391     "print(val_ss)"
392    ]
393   },
394   {
395    "cell_type": "code",
396    "execution_count": null,
397    "metadata": {
398     "id": "9eQpwUyGglu_"
399    },
400    "outputs": [],
401    "source": [
402     "def root_mean_squared_error(y_true, y_pred):\n",
403     "        return K.sqrt(K.mean(K.square(y_pred - y_true))) "
404    ]
405   },
406   {
407    "cell_type": "code",
408    "execution_count": null,
409    "metadata": {
410     "colab": {
411      "base_uri": "https://localhost:8080/"
412     },
413     "id": "1cKtTAzqyiyL",
414     "outputId": "e8cbfcc9-59f0-459a-a451-fd2d49c31973"
415    },
416    "outputs": [],
417    "source": [
418     "from keras.layers import Activation, Dense, Dropout\n",
419     "### Modelling using LSTM\n",
420     "steps = 50\n",
421     "\n",
422     "EPOCHS =20\n",
423     "\n",
424     "single_step_model = tf.keras.models.Sequential()\n",
425     "\n",
426     "single_step_model.add(tf.keras.layers.LSTM(32, return_sequences=False, input_shape = x_train_ss.shape[-2:]))\n",
427     "single_step_model.add(tf.keras.layers.Dropout(0.3))\n",
428     "single_step_model.add(tf.keras.layers.Dense(1))\n",
429     "single_step_model.compile(optimizer = tf.keras.optimizers.Adam(), loss = 'mae',metrics=[tf.keras.metrics.RootMeanSquaredError(name='rmse')])\n",
430     "#single_step_model.compile(loss='mse', optimizer='rmsprop')\n",
431     "single_step_model_history = single_step_model.fit(train_ss, epochs = EPOCHS , \n",
432     "                                                  steps_per_epoch =steps, validation_data = val_ss,\n",
433     "                                                  validation_steps = 50)\n",
434     "single_step_model.summary()\n",
435     "\n"
436    ]
437   },
438   {
439    "cell_type": "code",
440    "execution_count": null,
441    "metadata": {
442     "colab": {
443      "base_uri": "https://localhost:8080/",
444      "height": 281
445     },
446     "id": "Pgev0dgzzBVx",
447     "outputId": "21b2a7ee-356f-4ea9-b8e7-ba034e91c36e"
448    },
449    "outputs": [],
450    "source": [
451     "## plot train test loss \n",
452     "\n",
453     "def plot_loss(history , title):\n",
454     "  loss = history.history['loss']\n",
455     "  val_loss = history.history['val_loss']\n",
456     "\n",
457     "  epochs = range(len(loss))\n",
458     "  plt.figure()\n",
459     "  plt.plot(epochs, loss , 'b' , label = 'Train Loss')\n",
460     "  plt.plot(epochs, val_loss , 'r' , label = 'Validation Loss')\n",
461     "  plt.title(title)\n",
462     "  plt.legend()\n",
463     "  plt.grid()\n",
464     "  plt.show()\n",
465     "\n",
466     "plot_loss(single_step_model_history , 'Single Step Training and validation loss')"
467    ]
468   },
469   {
470    "cell_type": "code",
471    "execution_count": null,
472    "metadata": {
473     "colab": {
474      "base_uri": "https://localhost:8080/",
475      "height": 281
476     },
477     "id": "EnYf6j4okEoC",
478     "outputId": "b9f0c285-968c-4ada-828c-15f7d3a025c9"
479    },
480    "outputs": [],
481    "source": [
482     "## plot train test loss \n",
483     "\n",
484     "def plot_loss(history , title):\n",
485     "  loss = history.history['rmse']\n",
486     "  val_loss = history.history['val_rmse']\n",
487     "\n",
488     "  epochs = range(len(loss))\n",
489     "  plt.figure()\n",
490     "  plt.plot(epochs, loss , 'b' , label = 'Train RMSE')\n",
491     "  plt.plot(epochs, val_loss , 'r' , label = 'Validation RMSE')\n",
492     "  plt.title(title)\n",
493     "  plt.legend()\n",
494     "  plt.grid()\n",
495     "  plt.show()\n",
496     "\n",
497     "plot_loss(single_step_model_history , 'Single Step Training and validation loss')"
498    ]
499   },
500   {
501    "cell_type": "code",
502    "execution_count": null,
503    "metadata": {
504     "id": "WMegV8mNAwe_"
505    },
506    "outputs": [],
507    "source": [
508     "### fucntion to create time steps\n",
509     "def create_time_steps(length):\n",
510     "  return list(range(-length,0))\n",
511     "\n",
512     "### function to plot time series data\n",
513     "\n",
514     "def plot_time_series(plot_data, delta , title):\n",
515     "  labels = [\"History\" , 'True Future' , 'Model Predcited']\n",
516     "  marker = ['.-' , 'rx' , 'go']\n",
517     "  time_steps = create_time_steps(plot_data[0].shape[0])\n",
518     "\n",
519     "  if delta:\n",
520     "    future = delta\n",
521     "  else:\n",
522     "    future = 0\n",
523     "  plt.title(title)\n",
524     "  for i , x in enumerate(plot_data):\n",
525     "    if i :\n",
526     "      plt.plot(future , plot_data[i] , marker[i], markersize = 10 , label = labels[i])\n",
527     "    else:\n",
528     "      plt.plot(time_steps, plot_data[i].flatten(), marker[i], label = labels[i])\n",
529     "  plt.legend()\n",
530     "  plt.xlim([time_steps[0], (future+5) *2])\n",
531     "\n",
532     "  plt.xlabel('Time_Step')\n",
533     "  return plt"
534    ]
535   },
536   {
537    "cell_type": "code",
538    "execution_count": null,
539    "metadata": {
540     "id": "q99i2c-9XKF3"
541    },
542    "outputs": [],
543    "source": [
544     "### Moving window average\n",
545     "\n",
546     "def MWA(history):\n",
547     "  return np.mean(history)"
548    ]
549   },
550   {
551    "cell_type": "code",
552    "execution_count": null,
553    "metadata": {
554     "colab": {
555      "base_uri": "https://localhost:8080/",
556      "height": 1000
557     },
558     "id": "xFJT1rZDAUVL",
559     "outputId": "b91b2190-3709-431b-bf10-226a10d5b1ce"
560    },
561    "outputs": [],
562    "source": [
563     "# plot time series and predicted values\n",
564     "\n",
565     "for x, y in val_ss.take(5):\n",
566     "  plot = plot_time_series([x[0][:, 1].numpy(), y[0].numpy(),\n",
567     "                    single_step_model.predict(x)[0]], 12,\n",
568     "                   'Single Step Prediction')\n",
569     "  plot.show()"
570    ]
571   },
572   {
573    "cell_type": "markdown",
574    "metadata": {
575     "id": "_KXWQVmyCSix"
576    },
577    "source": [
578     "# **MultiStep Forcasting**"
579    ]
580   },
581   {
582    "cell_type": "code",
583    "execution_count": null,
584    "metadata": {
585     "colab": {
586      "base_uri": "https://localhost:8080/"
587     },
588     "id": "Lu7m2Rr4AbMK",
589     "outputId": "c9d7e6dc-0bc7-47c7-d46e-b3995916a961"
590    },
591    "outputs": [],
592    "source": [
593     "future_target = 72 # 72 future values\n",
594     "x_train_multi, y_train_multi = mutlivariate_data(features, features[:, 1], 0,\n",
595     "                                                 train_split, history,\n",
596     "                                                 future_target, STEP)\n",
597     "x_val_multi, y_val_multi = mutlivariate_data(features, features[:, 1],\n",
598     "                                             train_split, None, history,\n",
599     "                                             future_target, STEP)\n",
600     "\n",
601     "print(x_train_multi.shape)\n",
602     "print(y_train_multi.shape)"
603    ]
604   },
605   {
606    "cell_type": "code",
607    "execution_count": null,
608    "metadata": {
609     "id": "GLRv5D16CrHj"
610    },
611    "outputs": [],
612    "source": [
613     "#  TF DATASET\n",
614     "\n",
615     "train_data_multi = tf.data.Dataset.from_tensor_slices((x_train_multi, y_train_multi))\n",
616     "train_data_multi = train_data_multi.cache().shuffle(buffer_size).batch(batch_size).repeat()\n",
617     "\n",
618     "val_data_multi = tf.data.Dataset.from_tensor_slices((x_val_multi, y_val_multi))\n",
619     "val_data_multi = val_data_multi.batch(batch_size).repeat()"
620    ]
621   },
622   {
623    "cell_type": "code",
624    "execution_count": null,
625    "metadata": {
626     "colab": {
627      "base_uri": "https://localhost:8080/"
628     },
629     "id": "fjXexah9C8yg",
630     "outputId": "589003e9-f035-4c9b-bcf9-3377d047f0ef"
631    },
632    "outputs": [],
633    "source": [
634     "print(train_data_multi)\n",
635     "print(val_data_multi)"
636    ]
637   },
638   {
639    "cell_type": "code",
640    "execution_count": null,
641    "metadata": {
642     "colab": {
643      "base_uri": "https://localhost:8080/",
644      "height": 385
645     },
646     "id": "7mtLZ6S-DPU-",
647     "outputId": "7d37e336-cbae-4183-95c3-421271831727"
648    },
649    "outputs": [],
650    "source": [
651     "#plotting function\n",
652     "def multi_step_plot(history, true_future, prediction):\n",
653     "  plt.figure(figsize=(12, 6))\n",
654     "  num_in = create_time_steps(len(history))\n",
655     "  num_out = len(true_future)\n",
656     "  plt.grid()\n",
657     "  plt.plot(num_in, np.array(history[:, 1]), label='History')\n",
658     "  plt.plot(np.arange(num_out)/STEP, np.array(true_future), 'bo',\n",
659     "           label='True Future')\n",
660     "  if prediction.any():\n",
661     "    plt.plot(np.arange(num_out)/STEP, np.array(prediction), 'ro',\n",
662     "             label='Predicted Future')\n",
663     "  plt.legend(loc='upper left')\n",
664     "  plt.show()\n",
665     "  \n",
666     "\n",
667     "\n",
668     "for x, y in train_data_multi.take(1):\n",
669     "  multi_step_plot(x[0], y[0], np.array([0]))"
670    ]
671   },
672   {
673    "cell_type": "code",
674    "execution_count": null,
675    "metadata": {
676     "colab": {
677      "base_uri": "https://localhost:8080/"
678     },
679     "id": "snN_Flr5DWQN",
680     "outputId": "3c40a98f-b700-41e7-bc8e-36454edaf950"
681    },
682    "outputs": [],
683    "source": [
684     "multi_step_model = tf.keras.models.Sequential()\n",
685     "multi_step_model.add(tf.keras.layers.LSTM(32,\n",
686     "                                          return_sequences=True,\n",
687     "                                          input_shape=x_train_multi.shape[-2:]))\n",
688     "multi_step_model.add(tf.keras.layers.LSTM(16, activation='relu'))\n",
689     "#aDD dropout layer (0.3)\n",
690     "multi_step_model.add(tf.keras.layers.Dense(72)) # for 72 outputs\n",
691     "\n",
692     "multi_step_model.compile(optimizer=tf.keras.optimizers.RMSprop(clipvalue=1.0), loss='mae',metrics=[tf.keras.metrics.RootMeanSquaredError(name='rmse')])\n",
693     "\n",
694     "multi_step_history = multi_step_model.fit(train_data_multi, epochs=EPOCHS,\n",
695     "                                          steps_per_epoch=steps,\n",
696     "                                          validation_data=val_data_multi,\n",
697     "                                          validation_steps=50)"
698    ]
699   },
700   {
701    "cell_type": "code",
702    "execution_count": null,
703    "metadata": {
704     "colab": {
705      "base_uri": "https://localhost:8080/",
706      "height": 281
707     },
708     "id": "Ay5m27doDsTt",
709     "outputId": "b8ae8544-0723-4816-b0c7-4ad689b10506"
710    },
711    "outputs": [],
712    "source": [
713     "plot_loss(multi_step_history, 'Multi-Step Training and validation loss')"
714    ]
715   },
716   {
717    "cell_type": "code",
718    "execution_count": null,
719    "metadata": {
720     "colab": {
721      "base_uri": "https://localhost:8080/",
722      "height": 1000
723     },
724     "id": "6ZFP49W4D2wp",
725     "outputId": "faebe156-06e4-4b1d-fa8e-e6fbe45d95b5"
726    },
727    "outputs": [],
728    "source": [
729     "for x, y in val_data_multi.take(5):\n",
730     "  multi_step_plot(x[0], y[0], multi_step_model.predict(x)[0])"
731    ]
732   },
733   {
734    "cell_type": "code",
735    "execution_count": null,
736    "metadata": {
737     "colab": {
738      "base_uri": "https://localhost:8080/"
739     },
740     "id": "DNKMjVoAVqZP",
741     "outputId": "099fdbb3-cc5c-4831-b140-9732b75ff81d"
742    },
743    "outputs": [],
744    "source": [
745     "scores = multi_step_model.evaluate(x_train_multi, y_train_multi, verbose=1, batch_size=200)\n",
746     "print('MAE: {}'.format(scores[1]))"
747    ]
748   },
749   {
750    "cell_type": "code",
751    "execution_count": null,
752    "metadata": {
753     "colab": {
754      "base_uri": "https://localhost:8080/"
755     },
756     "id": "oDXXSFLy07gH",
757     "outputId": "6152b870-f63b-4142-9ec3-c774ed9b481c"
758    },
759    "outputs": [],
760    "source": [
761     "scores_test = multi_step_model.evaluate(x_val_multi, y_val_multi, verbose=1, batch_size=200)\n",
762     "print('MAE: {}'.format(scores[1]))\n"
763    ]
764   }
765  ],
766  "metadata": {
767   "accelerator": "GPU",
768   "colab": {
769    "collapsed_sections": [],
770    "name": "LSTM-correlation.ipynb",
771    "provenance": []
772   },
773   "kernelspec": {
774    "display_name": "Python 3 (ipykernel)",
775    "language": "python",
776    "name": "python3"
777   },
778   "language_info": {
779    "codemirror_mode": {
780     "name": "ipython",
781     "version": 3
782    },
783    "file_extension": ".py",
784    "mimetype": "text/x-python",
785    "name": "python",
786    "nbconvert_exporter": "python",
787    "pygments_lexer": "ipython3",
788    "version": "3.9.7"
789   }
790  },
791  "nbformat": 4,
792  "nbformat_minor": 1
793 }