How can I predict the weathers in the next days using LSTM or GRU?

63 Views Asked by At

I am a newbie in Deep learning and I am using Tensorflow, Keras. I was given a small task to predict the weather in the next days based on the past weather information sequence using neural networks. Example:

Given: snowy -> sunny -> rainy -> sunny -> sunny -> snowy -> rainy -> snowy -> sunny -> ? -> ?
(days) 1 2 3 4 5 6 7 8 9 10 11
Problem: predict the weather in days 10, 11 based on "n" days in the past.

I am planning to use LSTM or GRU for this task, but I am not sure how to do it properly. All I can think so far is to encode the weather using One-hot encoder as Snowy: 0 0 1 Rainy: 0 1 0 Sunny: 1 0 0 I do not know what to do next to train those One-hot encoded data with the LSTM or GRU networks. The code is below:

import numpy as np
import tensorflow
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import LSTM
lookBack = 3
stepsAhead = 2
categories = ["sunny", "rainy", "snowy"]
data = ["snowy", "sunny", "rainy", "sunny", "sunny", "snowy", "rainy", "snowy", "sunny"]
# Days   1         2        3        4        5        6        7        8        9

# Encode:
mapping = {}
for x in range(len(categories)):
  mapping[categories[x]] = x

one_hot_encode = []

for c in data:
  arr = list(np.zeros(len(categories), dtype = int))
  arr[mapping[c]] = 1
  one_hot_encode.append(arr)

print(one_hot_encode)
# The data after encoded: [[0, 0, 1], [1, 0, 0], [0, 1, 0], [1, 0, 0], [1, 0, 0],
# [0, 0, 1], [0, 1, 0], [0, 0, 1], [1, 0, 0]]

''' 
? ? ?
I do not know how to do the next steps such as: 
how to create a proper validation dataset, testing dataset, what LSTM structure 
should be used...
'''

Could I ask for your help on how to do it? I would be thankful if you show me some sample codes.

0

There are 0 best solutions below