Getting ready

For this recipe, we need to analyze the trend of the data prior to building the model.

First, let's import the keras library:

library(keras)

In this recipe, we will use the shampoo sales data, which can be downloaded from this book's GitHub repository. This dataset contains the monthly sales of shampoo over a 3-year period and consists of 36 rows. The original dataset is credited to Makridakis, Wheelwright, and Hyndman (1998):

data = read.table("data/shampoo_sales.txt",sep = ',')
data <- data[-1,]
rownames(data) <- 1:nrow(data)
colnames(data) <- c("Year_Month","Sales")
head(data)

The following screenshot shows a few records from the data:

Let's analyze the trend in the Sales column of the data:

# Draw a line plot to show the trend of data
library(ggplot2)
q = ggplot(data = data, aes(x = Year_Month, y = Sales,group =1))+ geom_line()
q = q+theme(axis.text.x = element_text(angle = 90, hjust = 1))
q

The following plot gives us an understanding of the trend in the data:

Here, we can see that there is an increasing trend in the data.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset