Save content
Have you found this content useful? Use the button above to save it to your profile.
artificial intelligence
istock_nielubieklonu_co

Coding for accountants: How to build a machine learning algorithm

by
7th Mar 2018
Save content
Have you found this content useful? Use the button above to save it to your profile.

Our goal in the next two parts of this series will be to train a machine learning algorithm to predict the UK unleaded petrol price from the price of brent crude oil.

This is what we call a “supervised” machine learning problem as we are given a training set containing both features (crude oil prices) along with their labels (unleaded petrol prices).

The other category viz. an “unsupervised” machine learning problem, looks at data sets which don’t contain labels, seeks to find hidden patterns in the data. A famous example of this was when a farm of Google computers taught itself to recognise cats from 10 million YouTube stills.

Introducing the problem

Our dataset will use the weekly (ultra low sulphur) unleaded petrol prices (£ pence per litre) published by the UK Department for Business, Energy & Industrial Strategy between June 2003 and February 2018. We’ve linked this with brent crude oil prices ($ per barrel) sourced from the U.S. Energy Information Administration.

It’s worth noting that we’ve simplified the problem somewhat, by not including a number of other features like the UK petrol duty rate, UK VAT rate (which ranged between 15-20% during this period) and the GBPUSD rate for example. The dataset can be downloaded here.

Once you’ve downloaded this data, go ahead and upload it to your Azure Notebooks library just like before. From here we can open a notebook and load the data as follows:

1

Visualising the data

To begin to understand the relationship between our crude_oil and petrol variables, it would be helpful to visualise the data we have here (768 weeks in total) on a scatter chart.

This is something we can already do in Excel, so let’s go a little further. For each dot on the scatter chart (x = crude_oil, y = petrol) we’ll also apply a colour scale depending on the date. By doing this it will be much easier to see trends over time (if there are any).

The code for this is as follows:

2

The code for this is a bit more involved when compared to previous plots, as it contains a “marker” attribute which we’ve used to define the colour scale we want.

Adding this colour scale turned out to be worth the effort as we can see an interesting clustering effect occurring between crude_oil and petrol depending on the date range.

3

Next week we’ll dig into this data further and apply a fairly common machine learning technique called “linear regression” to describe the relationship between the crude oil and unleaded petrol prices. An important aspect of this will be that we also get a level of confidence in the strength of the relationship between these two variables.

Click here to see the code we covered today.

Replies (2)

Please login or register to join the discussion.

avatar
By joebailey
12th Mar 2018 11:24

Interesting, the final link you posted doesn't work... if you repost I will take a look at this more deeply.

Thanks (0)
Replying to joebailey:
Jahan photo
By Jahan Zahid
15th Mar 2018 08:28

Hi Joe, it looks like the URL changed on Azure. You should be able to find it here:

https://notebooks.azure.com/jzahid/libraries/ai-series/html/Part5.ipynb

Thanks (0)