From Machine Learning for Business by Doug Hudgeon and Richard Nichol

This article covers basic time-series forecasting: what it is and why it’s a tough problem.


Save 37% on Machine Learning for Business. Just enter code fcchudgeon into the discount code box at checkout at

Forecasting your company’s monthly power usage

As an engineer, she reckons there must be a better way to approach this problem. In this article, you’ll use SageMaker to help Kiara produce better estimates of her company’s upcoming power consumption.

What are you making decisions about?

For example, figure 1 shows the predicted verses actual power consumption for one of Kiara’s sites for a six-week period from mid-October 2018 to the end of November. The site follows a weekly pattern with high usage on the weekdays and dropping low on Sunday.

The shaded blue area shows the range Kiara predicted with 80% accuracy. When Kiara calculates the average error for her prediction, she discovers it is 5.7%, which means that for any predicted amount, it is more likely to be within 5.7% of the predicted figure than not. Using SageMaker, you can do all of this without understanding in-depth how the neural network functions. In our view, this is OK.

Figure 1. Chart showing predicted verses actual power consumption for November 2018 for a site

To understand how neural networks can be used for time series forecasting, you need to understand why time-series forecasting is a thorny problem. Once you understand this, you’ll see what a neural network is and how a neural network can be applied to time-series forecasting. Then you’ll roll up your sleeves, fire up SageMaker, and see it in retailaction on real data.

The power consumption data you’ll use in this article is provided by BidEnergy (, a company that specializes in power-usage forecasting and in minimizing power expenditure. The algorithms used by BidEnergy are more sophisticated than you’ll see in this article but you’ll get a feel for how machine learning in general and neural networks in particular can be applied to forecasting problems.

Introduction to time series data

you created a time series of your weight, you could record your weight on the first of every month for a year. Your time series would have twelve observations with a numerical value for each observation. Table 1 shows what this might look like.

Table 1. table showing a person’s weight over the past year

It’s pretty boring to look at a table of data. It’s hard to get a real understanding of the data when it’s presented in a table format. Line charts are the best way to view time series data.

Figure 2 shows the same data presented as a chart.

Figure 2. Chart showing time series data of my weight over the past year

You can see from this time series that the date is on the left and your weight is on the right. if you wanted to record time series of body weight for your entire family you’d add a column for each of your family members. In table 2 you can see your weight and the weight of each of your family members over the course of a year.

Table 2. Table showing the weight of members of a family over a year

And, once you have that, you can visualize the data as four separate charts as shown in figure 3.

Figure 3. Chart showing time series data of the weight of members of a family over the past year

Kiara’s time series data: daily power consumption

This data looks similar to the data in figure 3 showing the weight of each family member each month. The difference is that instead of each column representing a family member, in Kiara’s data each column represents a site (office/warehouse location) for her company. And instead of each row representing a person’s weight on the first day of the month, each row of Kiara’s data shows how much power each site used on that day.

Table 3. Power usage data sample (half-hour intervals)

Now that you see how time-series data can be represented and visualized, the next step is to see how to use a Jupyter notebook to visualize this data.

That, however, is where we will stop for this article. If you want to learn more about the book, check it out on liveBook here and see this slide deck.

Originally published at

Follow Manning Publications on Medium for free content and exclusive discounts.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store