00BER commited on
Commit
f8457a8
1 Parent(s): 78730ab

Upload 19 files

Browse files
README.md ADDED
@@ -0,0 +1 @@
 
 
1
+ Weather forecasting using machine learning
docs/.DS_Store ADDED
Binary file (6.15 kB). View file
 
docs/base-1.png ADDED
docs/base-2.png ADDED
docs/comparision.png ADDED
docs/correlations.png ADDED
docs/day-of-year.png ADDED
docs/graph-view.png ADDED
docs/interpolation.png ADDED
docs/lstm.png ADDED
docs/main.tex ADDED
@@ -0,0 +1,536 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2
+ % LaTeX Example: Project Report
3
+ %
4
+ % Source: http://www.howtotex.com
5
+ %
6
+ % Feel free to distribute this example, but please keep the referral
7
+ % to howtotex.com
8
+ % Date: March 2011
9
+ %
10
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
11
+ % How to use writeLaTeX:
12
+ %
13
+ % You edit the source code here on the left, and the preview on the
14
+ % right shows you the result within a few seconds.
15
+ %
16
+ % Bookmark this page and share the URL with your co-authors. They can
17
+ % edit at the same time!
18
+ %
19
+ % You can upload figures, bibliographies, custom classes and
20
+ % styles using the files menu.
21
+ %
22
+ % If you're new to LaTeX, the wikibook is a great place to start:
23
+ % http://en.wikibooks.org/wiki/LaTeX
24
+ %
25
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
26
+ % Edit the title below to update the display in My Documents
27
+ %\title{Project Report}
28
+ %
29
+ %%% Preamble
30
+ \documentclass[paper=a4, fontsize=11pt, margin=1in]{scrartcl}
31
+ \usepackage[T1]{fontenc}
32
+ \usepackage{fourier}
33
+ \usepackage{longtable}
34
+ \usepackage[english]{babel} % English language/hyphenation
35
+ \usepackage[protrusion=true,expansion=true]{microtype}
36
+ \usepackage{amsmath,amsfonts,amsthm} % Math packages
37
+ \usepackage[pdftex]{graphicx}
38
+ \usepackage{url}
39
+ \usepackage[colorlinks=true]{hyperref}
40
+ \usepackage{multicol}
41
+ \setlength{\footskip}{120pt}
42
+ \usepackage{caption}
43
+ \usepackage{subcaption}
44
+
45
+ %%% Custom sectioning
46
+ \usepackage{sectsty}
47
+ \allsectionsfont{\centering \normalfont\scshape}
48
+
49
+
50
+ %%% Custom headers/footers (fancyhdr package)
51
+ \usepackage{fancyhdr}
52
+ \pagestyle{fancyplain}
53
+ \fancyhead{} % No page header
54
+ \fancyfoot[L]{} % Empty
55
+ \fancyfoot[C]{} % Empty
56
+ \fancyfoot[C]{\thepage} % Pagenumbering
57
+ \renewcommand{\headrulewidth}{0pt} % Remove header underlines
58
+ \renewcommand{\footrulewidth}{0pt} % Remove footer underlines
59
+ \setlength{\headheight}{13.6pt}
60
+
61
+
62
+ %%% Equation and float numbering
63
+ \numberwithin{equation}{section} % Equationnumbering: section.eq#
64
+ \numberwithin{figure}{section} % Figurenumbering: section.fig#
65
+ \numberwithin{table}{section} % Tablenumbering: section.tab#
66
+
67
+ \setlength{\parindent}{0pt}
68
+ %%% Maketitle metadata
69
+ \newcommand{\horrule}[1]{\rule{\linewidth}{#1}} % Horizontal rule
70
+
71
+ \title{
72
+ %\vspace{-1in}
73
+ \usefont{OT1}{bch}{b}{n}
74
+ \normalfont \normalsize \textsc{University of Maryland Science Academy} \\ [25pt]
75
+ \horrule{0.5pt} \\[0.4cm]
76
+ \huge Using deep learning to predict the temperature of the next 24 hours at the \\
77
+ Ronald Reagan National Airport \\
78
+ \horrule{2pt} \\[0.5cm]
79
+ }
80
+ \author{
81
+ \normalfont \normalsize
82
+ Sushant Karki\\[-3pt] \normalsize
83
+ \today
84
+ }
85
+ \date{}
86
+
87
+ \setlength{\parindent}{0pt}
88
+
89
+ %%% Begin document
90
+ \begin{document}
91
+ \maketitle
92
+ \section{\textbf{Abstract}}
93
+ Weather forecasts are an integral part of our day-to-day lives. They help us plan ahead and be prepared for the upcoming hours, days and even weeks. We use the weather apps on our phones to check tomorrow's temperature or the chances of rain in order to dress appropriately or to make sure we take our umbrellas with us. These are all weather forecasts that we use regularly without giving a second thought.\\
94
+
95
+ As it is such an important part of our lives, the accuracy of these forecasts are very important. Not all weather forecasts are made equal as meteorologists use a variety of approaches and a wide range of data to make predictions. \\
96
+
97
+ One emerging approach in the field of weather forecasting is the use of machine learning to make predictions. The abundance of data being collected these days and the increasing advancements in machine learning algorithms make this a task that machine learning is really suited for.\\
98
+
99
+ This project is an attempt in using machine learning (deep learning in particular) to make hourly weather forecasts for each day at Washington D.C.
100
+
101
+ \break
102
+
103
+ \section{\textbf{Problem Definition and Algorithm}}
104
+
105
+ \subsection{\textbf{Task Definition: }}
106
+ Using historical hourly weather data of the previous 7 days, predict the temperature for the next 24 hours (12am to next day's 12am).
107
+
108
+ \subsection{\textbf{Source of Data}}
109
+
110
+ \textbf{URL:} \href{https://www.wunderground.com/history/daily/us/va/arlington/KDCA/date/2022-12-12}{Wunderground}\\
111
+
112
+ Under the hood, Wunderground sends an HTTP request to \textbf{https://api.weather.com} which returns historical hourly data for a particular date and location. \\
113
+
114
+ The format of the data is as follows:\\
115
+
116
+
117
+ \begin{longtable}{|p{4.5cm}|p{7cm} |p{3cm}|} % centered columns (4 columns)
118
+ \hline\hline %inserts double horizontal lines
119
+ \textbf{Field} & \textbf{Description} & \textbf{Example} \\ % inserts table
120
+ %heading
121
+ \hline
122
+ key & Observation weather station ID & KDCA \\
123
+ \hline
124
+ class & Type of data& observation \\
125
+ \hline
126
+ expire\_time\_gmt & Expiration time in UNIX seconds & 1669881120 \\
127
+ \hline
128
+ obs\_id & Observation weather station ID & KDCA \\
129
+ \hline
130
+ obs\_name & & Washington/Natl \\
131
+ \hline
132
+ valid\_time\_gmt & Valid time in UNIX seconds. This is the date and time that the observation was made & 1669873920 \\
133
+ \hline
134
+ day\_ind & Time of day of the observation. \newline D = Day \newline N = Night& N \\
135
+ \hline
136
+ temp & The observed temperature & 42 \\
137
+ \hline
138
+ wx\_icon & The two-digit number to represent the observed weather conditions. & 33 \\
139
+ \hline
140
+ icon\_extd & Code representing explicit full set sensible weather & 3300 \\
141
+ \hline
142
+ wx\_phrase & A text description of the observed weather conditions at the reporting station & \\
143
+ \hline
144
+ pressure\_tend & The change in the barometric pressure reading over the last hour expressed as an integer. \newline 0 = Steady \newline
145
+ 1 = Rising or Rapidly Rising \newline
146
+ 2 = Falling or Rapidly Falling & 0 \\
147
+ \hline
148
+ pressure\_desc & A phrase describing the change in the barometric pressure reading over the last hour. \newline (Steady,
149
+ Rising,
150
+ Rapidly Rising,
151
+ Falling, Rapidly Falling) & Steady \\
152
+ \hline
153
+ dewPt & The temperature which air must be cooled at constant pressure to reach saturation. The Dew Point is
154
+ also an indirect measure of the humidity of the air. The Dew Point will never exceed the Temperature.
155
+ When the Dew Point and Temperature are equal, clouds or fog will typically form. The closer the values
156
+ of Temperature and Dew Point, the higher the relative humidity. & 60 \\
157
+ \hline
158
+ heat\_index & An apparent temperature. It represents what the air temperature “feels like” on exposed human skin
159
+ due to the combined effect of warm temperatures and high humidity.
160
+ When the temperature is 70°F or higher, the Feels Like value represents the computed Heat Index.
161
+ For temperatures between 40°F and 70°F, the Feels Like value and Temperature are the same,
162
+ regardless of wind speed and humidity, so use the Temperature value. & 70 \\
163
+ \hline
164
+ rh & The relative humidity of the air, which is defined as the ratio of the amount of water vapor in the air to
165
+ the amount of vapor required to bring the air to saturation at a constant temperature. Relative humidity
166
+ is always expressed as a percentage. & 91\\
167
+ \hline
168
+ pressure & Barometric pressure is the pressure exerted by the atmosphere at the earth's surface, due to the weight
169
+ of the air. This value is read directly from an instrument called a mercury barometer and its units are
170
+ expressed in millibars (equivalent to HectoPascals). & 30.06 \\
171
+ \hline
172
+ vis & The horizontal visibility at the observation point. Visibilities can be reported as fractional values
173
+ particularly when visibility is less than 2 miles. Visibilities greater than 10 statute miles(16.1 kilometers)
174
+ which are considered “unlimited” are reported as “999” in your feed. You can also find visibility values
175
+ that equal zero. This occurrence is not wrong. Dense fogs and heavy snows can produce values near
176
+ zero. Fog, smoke, heavy rain and other weather phenomena can reduce visibility to near zero miles or
177
+ kilometers. & 10 \\
178
+ \hline
179
+ wc & An apparent temperature. It represents what the air temperature “feels like” on exposed human skin
180
+ due to the combined effect of the cold temperatures and wind speed.
181
+ When the temperature is 61°F or lower the Feels Like value represents the computed Wind Chill so
182
+ display the Wind Chill value.
183
+ For temperatures between 61°F and 75°F, the Feels Like value and Temperature are the same,
184
+ regardless of wind speed and humidity, so display the Temperature value. & -25\\
185
+ \hline
186
+ wdir & The direction from which the wind blows expressed in degrees. The magnetic direction varies from 1 to
187
+ 360 degrees, where 360° indicates the North, 90° the East, 180° the South, 270° the West, and so
188
+ forth. A ‘null’ value represents no determinable wind direction. & 45 \\
189
+ \hline
190
+ wdir\_cardinal & This field contains the cardinal direction from which the wind blows in an abbreviated form. Wind
191
+ directions are always expressed as “from whence the wind blows” meaning that a North wind blows
192
+ from North to South. If you face North in a North wind, the wind is at your face. Face southward and the
193
+ North wind is at your back.
194
+ (N , NNE , NE, ENE, E, ESE, SE,
195
+ SSE, S, SSW, SW, WSW, W,
196
+ WNW, NW, NNW, CALM, VAR) & WSW \\
197
+ \hline
198
+ gust & Wind gust speed.
199
+ This data field contains information about sudden and temporary variations of the average Wind Speed.
200
+ The report always shows the maximum wind gust speed recorded during the observation period. It is a
201
+ required display field if Wind Speed is shown. The speed of the gust can be expressed in miles per
202
+ hour or kilometers per hour. & 35\\
203
+ \hline
204
+ wspd & Wind Speed.
205
+ The wind is treated as a vector; hence, winds must have direction and magnitude (speed). The wind
206
+ information reported in the hourly current conditions corresponds to a 10-minute average called the
207
+ sustained wind speed. Sudden or brief variations in the wind speed are known as “wind gusts” and are
208
+ reported in a separate data field.
209
+ Wind directions are always expressed as "from whence the wind blows" meaning that a North wind
210
+ blows from North to South. If you face North in a North wind the wind is at your face. Face southward
211
+ and the North wind is at your back. & 15 \\
212
+ \hline
213
+ max\_temp & High temperature in the last 24 hours & 81 \\
214
+ \hline
215
+ min\_temp & Low temperature in the last 24 hours & 48\\
216
+ \hline
217
+ precip\_total & Precipitation amount in the last rolling 24 hour period & 0.3 \\
218
+ \hline
219
+ precip\_hourly & Precipitation for the last hour & 0.5 \\
220
+ \hline
221
+ snow\_hourly & Snow increasing rapidly in inches or
222
+ centimeters per hour depending on whether
223
+ the snowfall is reported by METAR or TECCI
224
+ (synthetic observations). METAR snow
225
+ accumulation is in inches and TECCI is in
226
+ centimeters & 1\\
227
+ \hline
228
+ uv\_desc & Ultraviolet index description \newline (Extreme, High, Low, Minimal, Moderate, No Report, Not Available)& High \\
229
+ \hline
230
+ feels\_like & An apparent temperature. It represents what the air temperature “feels like” on exposed human skin
231
+ due to the combined effect of the wind chill or heat index. & 60 \\
232
+ \hline
233
+ uv\_index & Ultraviolet index \newline (0 to 11 and 999) & 7 \\
234
+ \hline
235
+ qualifier & Weather description qualifier code & QQ0063 \\
236
+ \hline
237
+ qualifier\_svrty & Weather description qualifier severity \newline (1 to 6)& 1\\
238
+ \hline
239
+ blunt\_phrase & Weather description qualifier short phrase & Warmer than yesterday.\\
240
+ \hline
241
+ terse\_phrase & Weather description qualifier terse phrase & Dangerous wind chills. Limit outdoor exposure. \\
242
+ \hline
243
+ clds & Cloud cover description code \newline (SKC, CLR, SCT, FEW, BKN, OVC) & SKC \\
244
+ \hline
245
+ water\_temp & Water temperature & 80\\
246
+ \hline
247
+ primary\_wave\_period & Primary wave period & 13\\
248
+ \hline
249
+ primary\_wave\_height & Primary wave height & 3.28\\
250
+ \hline
251
+ primary\_swell\_period & Primary swell period & 13\\
252
+ \hline
253
+ primary\_swell\_height & Primary swell height & 1.64\\
254
+ \hline
255
+ primary\_swell\_direction & Primary swell direction & 190\\
256
+ \hline
257
+ secondary\_swell\_period & Secondary swell period & null\\
258
+ \hline
259
+ secondary\_swell\_height & Secondary swell height & null\\
260
+ \hline
261
+ secondary\_swell\_direction & Secondary swell direction & null\\
262
+ \hline %inserts single line
263
+ \end{longtable}
264
+
265
+ \subsection{\textbf{Choice of algorithm}}
266
+ Since this is a time-series forecasting problem, the Long Short Term Memory (LSTM) neural network was used to build the model. For the look-back period, a period of 7 days(168 hours) were chosen. And since prediction needs to be made for the next 24 hours a multi-step (24 steps) model was trained.\\
267
+
268
+ A vanilla Recursive Neural Network (RNN) only has a short term memory because it suffers from the vanishing gradients problem. This occurs because during backpropagation in a vanilla RNN, only the recent hidden states are remembered as the gradients for earlier layers get exponentially smaller and don't do much learning at all. An LSTM is much more robust to vanishing gradients and can remember information from earlier inputs much better than a vanilla RNN. \\
269
+
270
+ My assumption for the prediction problem is that temperature for a particular day not only depends on the day before, but on the weather conditions for a longer timespan (the entire past week). For this reason, LSTM was chosen as it remembers hidden states from the earlier timesteps better.\\
271
+
272
+ \begin{center}
273
+ \includegraphics[width=0.8\textwidth,height=0.5\textheight]{lstm.png}
274
+ \\
275
+ Fig: A simplistic LSTM representation of the modeling task
276
+ \end{center}
277
+
278
+
279
+ \section{\textbf{Exploratory Data Analysis}}
280
+
281
+ 22 years worth of historical hourly weather data from 2000-01-01 to 2000-12-06 for the Ronald Reagan National Airport was used for training the model. This amounted to a total of \textbf{247349} rows of weather data records.\\
282
+
283
+ The first step was to figure out which columns were actually usable in my dataset. For that, I first loaded the data into a pandas DataFrame and checked the NaN counts for each column. I found that almost half of columns were NaN. \\
284
+
285
+ \begin{center}
286
+ \includegraphics[width=\textwidth]{nan-counts.png}
287
+ \end{center}
288
+
289
+ Using this information, I decided to keep only the following columns (ones that are almost always recorded during observations):\\
290
+ \raggedcolumns
291
+ \begin{multicols}{4}
292
+ \begin{itemize}
293
+ \item temp
294
+ \item valid\_time\_gmt
295
+ \item pressure
296
+ \item wspd
297
+ \item heat\_index
298
+ \item dewPt
299
+ \item rh
300
+ \item vis
301
+ \item wc
302
+ \item clds
303
+ \item wdir\_cardinal
304
+ \end{itemize}
305
+ \end{multicols}
306
+
307
+ \pagebreak
308
+
309
+ The next step was to check the columns and see how they were correlated. Just by the column definitions, I knew that heat\_index and wc would be highly correlated to the temperature, but had no idea about how the other columns were related. Using seaborn to plot the correlations, I got the following graph:\\
310
+
311
+ \begin{center}
312
+ \includegraphics[width=1\textwidth,height=0.5\textheight]{correlations.png}
313
+ \\
314
+ Fig: Correlation among the columns
315
+ \end{center}
316
+
317
+ Some findings that I took away were that dewPt is highly correlated to the temperature, relative humidity (rh) is highly correlated to the the visibility (vis), and there is also a slight correlation between the pressure and the temperature.
318
+
319
+ \section{\textbf{Data Preprocessing}}
320
+
321
+ Since I want to convert the data into fixed width hourly records, the first step was to convert the UNIX timestamp to a human readable date. This was easily done with the python datetime library.
322
+
323
+ After converting the unix timestamps into datetime objects, I found that the time the observations are made are not made uniformly. As can be seen from the following screenshot, the observations are not all taken at the same hour.
324
+
325
+ \begin{center}
326
+ \includegraphics[width=1\textwidth,height=0.5\textheight]{time-of-hour.png}\\
327
+ Fig: Graph showing number of observations made at specific minutes of an hour
328
+ \end{center}
329
+
330
+ On further analysis, it became clear that while the observations in first few years of our timespan (2000~2010), the observations were not made at regular intervals, the more recent years had regular intervals. Especially, as evident in the graph above, almost all hourly records had data for the 52\textsuperscript{nd} minute. Thus, I decided to use all the 52\textsuperscript{nd} minute observations as data for our modeling.
331
+
332
+ Despite there to be a lot of 52\textsuperscript{nd} minute data in the dataset, I had many missing observations (missing a few hours in some days). Since my LSTM model uses each of the previous 168 hours data as input to make predictions, missing data would cause inaccuracies in my model. To fix this, I used the following interpolations and backfill/forwardfill to fill in the missing rows and created a uniformly spaced timeseries dataframe for training:
333
+
334
+ \begin{longtable}{|p{4.5cm}|p{3cm}|p{7cm}|} % centered columns (4 columns)
335
+ \hline\hline %inserts double horizontal lines
336
+ \textbf{Field} & \textbf{Fill Type} & \textbf{Parameters} \\ % inserts table
337
+ %heading
338
+ \hline
339
+ temp & Interpolation & Polynomial, order=2 \\
340
+ \hline
341
+ heat\_index & Interpolation & Polynomial, order=2 \\
342
+ \hline
343
+ pressure & Interpolation & Polynomial, order=2 \\
344
+ \hline
345
+ wspd & Interpolation & Polynomial, order=2 \\
346
+ \hline
347
+ dewPt & Interpolation & Polynomial, order=2 \\
348
+ \hline
349
+ rh & Interpolation & Polynomial, order=2 \\
350
+ \hline
351
+ wc & Interpolation & Polynomial, order=2 \\
352
+ \hline
353
+ wdir\_cardinal & Backfill & \\
354
+ \hline
355
+ vis & Backfill & \\
356
+ \hline
357
+ clds & Interpolation & Linear (Transformed categorical to ordinal and performed interpolation) \\
358
+ \hline
359
+ \end{longtable}
360
+
361
+ \begin{center}
362
+ \includegraphics[scale=0.7]{interpolation.png}
363
+ \\
364
+ Fig: An example of interpolation performed to fill missing 52\textsuperscript{nd} minute temperature values
365
+ \end{center}
366
+
367
+ One big part of predicting weather is to note that weather conditions are cyclical in nature. i.e. weather conditions in January of one year are similar to weather conditions of January of the next year, weather conditions at 1 am today is close distance-wise to weather conditions at 1 am in other days. Directly incorporating the timestamp as a feature would lose this cyclical information. So, I transformed the timestamps (hour of day, day of year) into sin and cosine waves to preserve the cyclical information.
368
+
369
+ \begin{center}
370
+ \includegraphics[scale=0.4]{time-of-day.png}
371
+ \\
372
+ Fig: Hour of day encoded as sine/cosine wave
373
+ \end{center}
374
+
375
+ \begin{center}
376
+ \includegraphics[scale=0.4]{day-of-year.png}
377
+ \\
378
+ Fig: Day of year encoded as sine/cosine wave
379
+ \end{center}
380
+
381
+ With this, the dataset was ready and I moved on to the training portion of the project.
382
+
383
+ \pagebreak
384
+ \section{\textbf{Training}}
385
+
386
+ The dataset was split into 70:20:10 train, validation and test sets.
387
+ A StandardScaler was fit into the train dataset and all the train, validation and test sets were standardized with this scaler.
388
+
389
+ The most crucial step for my model was to generate the sequence of inputs to feed into my LSTM layer.
390
+ Since my approach was to use the last 168 hours of weather data as the lookback for the model, generating the sequence of inputs was a little confusing at first. But thanks to \href{https://www.tensorflow.org/tutorials/structured_data/time_series#data_windowing}{this excellent
391
+ tensorflow tutorial}, I was able to set it up just right.\\
392
+
393
+ After generating the sequences, my training data looked like the following:
394
+
395
+ \begin{center}
396
+ \includegraphics[width=1.2\textwidth]{training-data.png}
397
+ \\
398
+ Fig: Training Data after sequencing
399
+ \end{center}
400
+
401
+ From the above figure, we can see that for each sample in our training data, the past 168 hours of data have been correctly set up as input features and the next 24 hours have been set aside as labels for training.
402
+
403
+ I experimented with stacked LSTM, adding more dense layers, varying LSTM unit counts, and so on. But considering the training time constraints and performance, I found the following model to give the best results for me:
404
+
405
+ \begin{longtable}{|p{4.5cm}|p{3cm}|p{7cm}|} % centered columns (4 columns)
406
+ \hline\hline %inserts double horizontal lines
407
+ \textbf{Layer (type)} & \textbf{Output Shape} & \textbf{Param \#} \\ % inserts table
408
+ %heading
409
+ \hline
410
+ \hline
411
+ lstm\_2 (LSTM) & (None, 12) & 1248 \\
412
+ \hline
413
+ dense\_2 (Dense) & (None, 24) & 312 \\
414
+ \hline
415
+ reshape\_2 (Reshape) & (None, 24, 1) & 0 \\
416
+ \hline
417
+ \end{longtable}
418
+
419
+ \begin{longtable}{|p{4.5cm}|}
420
+ \hline
421
+ \textbf{Total params}: 1,560 \\
422
+ \textbf{Trainable params}: 1,560 \\
423
+ \textbf{Non-trainable params}: 0\\
424
+ \hline
425
+ \end{longtable}
426
+
427
+ \textbf{Framework: } Tensorflow, Keras\\
428
+ \textbf{Choice of optimizer:} Adam with learning rate of 1e-3, default decay\\
429
+ \textbf{Choice of loss function: } Mean Absolute Error\\
430
+ I chose MAE as my loss because it was easier to comprehend and the model converged considerably well for my project.
431
+
432
+ \textbf{Max Epochs: } 100 ( I used Early Stopping with a patience of 5 such that if the validation loss didn't go down for 5 straight epochs, the model would stop training further )\\
433
+ \\
434
+ The model was configured to save every epoch if the validation loss improved from the previous best.
435
+
436
+ The best model had a validation loss of 3.5005.\\
437
+
438
+ Although the Mean Absolute Error gave an idea of how accurate my model was, I found it useful to compare it to a baseline model. Thus, for evaluation of my model, I created the following baseline models and trained them on the same dataset:
439
+
440
+ \begin{center}
441
+ \includegraphics[width=0.93\textwidth]{base-1.png}\\
442
+ Fig: Baseline model that predicts a constant temperature no matter what the input.\\
443
+ \end{center}
444
+
445
+ \begin{center}
446
+ \includegraphics[width=1\textwidth]{base-2.png}\\
447
+ Fig: Baseline model that just repeats the previous day's temperatures as predictions
448
+ \end{center}
449
+
450
+ \pagebreak
451
+ Looking at the following graph of the LSTM's performance on test data, it seems that the LSTM model is indeed making more accurate predictions.\\
452
+ \begin{center}
453
+ \includegraphics[scale=0.6]{model-eval.png}\\
454
+ Fig: Samples of LSTM model's performance on test dataset\\
455
+ \end{center}
456
+
457
+ Comparing the average Mean Absolute Error for all three models, the following results were seen:\\
458
+ \begin{center}
459
+ \includegraphics[width=\textwidth,height=0.3\textheight]{comparision.png}\\
460
+ Fig: Comparison of the LSTM model's performance vs the two baseline models
461
+ \end{center}
462
+
463
+ \section{\textbf{Making Predictions / User Interface}}
464
+
465
+ After building my model, I built a website that uses this model and allows a user to check the model's forecasts for tomorrow's temperature for Washington D.C. The website also shows its past predictions and compares them with the actual temperatures for that day to give a sense of how accurate the model actually is.//
466
+
467
+ The website is available at \href{http://3.235.0.237/#/dashboard}{\textbf{http\://3.235.0.237/\#/dashboard}}.
468
+
469
+
470
+ \subsection{\textbf{Technology Stack}}
471
+
472
+
473
+ \begin{longtable}{|p{4.5cm}|p{7cm}|}
474
+ \hline
475
+ \textbf{Backend} & Flask, Tensorflow \\
476
+ \hline
477
+ \textbf{Frontend} & Angular \\
478
+ \hline
479
+ \textbf{Infra} & AWS EC2, Docker \\
480
+ \hline
481
+ \end{longtable}
482
+
483
+ \subsection{\textbf{Architecture}}
484
+ \begin{center}
485
+ \includegraphics[width=1\textwidth]{weather-requests.drawio.png}\\
486
+ Fig: Request/Response life cycle
487
+ \end{center}
488
+ \pagebreak
489
+
490
+ \subsection{\textbf{User Interface}}
491
+
492
+ The user interface consists of a horizontal scrollable date picker that allows the user to select a date (from the current date to 30 days before the current date) to look at predictions for. The rightmost date is the current date. For the current date, since we don't know the full day actual data yet, the predictions from the model are shown along with the actual temperatures until the time the site is accessed at. The actual temperature for future times will be shown once observation data is available from the weather API.\\
493
+
494
+ Selecting a date plots the predicted temperature vs the actual temperature for that date in a line graph. The red dotted line indicates the predicted temperature, blue solid one shows the actual temperature for that day. The shaded gray area indicates the absolute error in the prediction. Apart from the graph, the page also contains a tabular view of the same data at the lower half of the page.\\
495
+
496
+
497
+ \begin{center}
498
+ \includegraphics[width=1\textwidth]{graph-view.png}\\
499
+ Fig: Graph View
500
+ \end{center}
501
+
502
+ \begin{center}
503
+ \includegraphics[width=1\textwidth,height=0.3\textheight]{table-view.png}\\
504
+ Fig: Table View
505
+ \end{center}
506
+
507
+ \section{\textbf{Conclusion}}
508
+ The final model had a Mean Absolute Error score of about 3.5. i.e. our model's predicted temperatures are about $\pm3.5$ from the actual temperature. Although the accuracy is not as high as I would have liked, looking at the predicted vs the actual temperatures, it seems that the model is capturing the trend (increasing or decreasing) relatively accurately. \\
509
+
510
+ To improve the model further, I would like to add more important features (perhaps from a completely new dataset) and see how it performs. Although I experimented with the architecture of the neural network, due to time constraints, I wasn't able to experiment as much as I would have liked. So, I definitely want to try different LSTM architectures in the near future and see how they compare to my current model.
511
+
512
+ \section{\textbf{References}}
513
+
514
+ \begin{itemize}
515
+ \item Educational Resources
516
+ \begin{itemize}
517
+ \item \href{https://www.tensorflow.org/tutorials/structured_data/time_series#multi-step_models}{Time series forecasting - Tensorflow}
518
+ \item \href{https://keras.io/examples/timeseries/timeseries_weather_forecasting/}{Timeseries forecasting for weather prediction \- Prabhanshu Attri, Yashika Sharma, Kristi Takach, Falak Shah}
519
+
520
+ \item \href{https://towardsdatascience.com/single-and-multi-step-temperature-time-series-forecasting-for-vilnius-using-lstm-deep-learning-b9719a0009de}{Single and Multi\-Step Temperature Time Series Forecasting for Vilnius Using LSTM Deep Learning Model, Eligijus Bujokas}
521
+ \end{itemize}
522
+ \item Dataset
523
+ \begin{itemize}
524
+ \item \href{https://www.wunderground.com/}{API: Weather Underground}
525
+ \item \href{https://www.worldcommunitygrid.org/lt/images/climate/The_Weather_Company_APIs.pdf}{Dataset descriptions}
526
+ \end{itemize}
527
+ \item Project Artifacts
528
+ \begin{itemize}
529
+ \item \href{http://3.235.0.237/#/dashboard}{Website URL}
530
+ \item \href{https://colab.research.google.com/drive/1G6E8fT-viMPYw1fnWnBho2ONFfIyAXbK#scrollTo=ykqO9SfV9t7x}{Colab used for training}
531
+ \item \href{https://github.com/00ber/ml-weather-prediction}{Source code}
532
+ \end{itemize}
533
+ \end{itemize}
534
+
535
+ %%% End document
536
+ \end{document}
docs/model-eval.png ADDED
docs/nan-counts.png ADDED
docs/table-view.png ADDED
docs/time-of-day.png ADDED
docs/time-of-hour.png ADDED
docs/training-data.png ADDED
docs/ui.png ADDED
docs/weather-requests.drawio.png ADDED