We will now demonstrate an example of an LSTM implemented in keras to solve a simple time series prediction problem:
- Import all the required libraries as follows:
%matplotlib inline
import numpy
import matplotlib.pyplot as plt
from pandas import read_csv
import math
from keras.models import Sequential
from keras.layers import Dense
from keras.layers import LSTM
from sklearn.preprocessing import MinMaxScaler
from sklearn.metrics import mean_squared_error
import os
import numpy as np
import math
# Necessary for some OSX version
os.environ['KMP_DUPLICATE_LIB_OK'] = 'True'
# fix a random seed for reproducibility
numpy.random.seed(11)
- Define a few parameters that will be important for later on, as follows:
LEN_DATASET = 100
EPOCHS = 50
BATCH_SIZE = 1
# It's going to be used to
# reshape into X=t and Y=t+1
look_back = 1
- Create the dataset as follows:
sin_wave...