In this recipe, we will learn how to use the LSTM implementation of Keras to predict sales based on a historical dataset. We will use the same dataset we used earlier for predicting shampoo sales.
The dataset is in the sales-of-shampoo-over-a-three-ye.csv
file:
"Month","Sales of shampoo over a three year period" "1-01",266.0 "1-02",145.9 "1-03",183.1 "1-04",119.3 "1-05",180.3 "1-06",168.5 "1-07",231.8
First, we need to import the relevant classes as follows:
from pandas import read_csv from matplotlib import pyplot from pandas import datetime
def parser(x): return datetime.strptime('200' + x, '%Y-%m')
- Next, call the
read_csv
function of pandas to load a.csv
into aDataFrame
as follows:
series = read_csv('sales-of-shampoo-over-a-three-ye.csv', header=0, parse_dates=[0], index_col=0, squeeze=True, date_parser=parser)
- Summarize the first few rows using the following code:
print(series...