{ "cells": [ { "cell_type": "markdown", "id": "09fe27ef", "metadata": {}, "source": [ "# Optimising the timing of paid media spend\n", "\n", "What is the best way of splitting a media budget across the year? [Two weeks ago](/anvil/paid-media-forecasting/) I wrote an introduction to forecasting paid media; in this post I will develop the ideas further to show you how to use a machine learning forecasting model to figure out how much you should spend on a channel across the year.\n", "\n", "The big idea here is that if you have a forecast that uses daily spend as a regressor column (see the [last post](/anvil/paid-media-forecasting/) for more on this) then you can estimate what would happen in the future if you spent different amounts each day e.g. \"what would happen if we spent 10% more on April 12th?\"\n", "\n", "This can be quite useful by itself but you can take things to another level by asking the computer to test lots of different spend levels on each day in order to find the optimal values. If you have a good forecast model then this process can find the perfect balance between the diminishing returns of increasing spend and the fact that at some times of year there is more demand and higher conversion rates. Very cool!\n", "\n", "In this post I will walk you through how to do this. Unfortunately this isn't possible in the Forecast Forge Google Sheets addon because the addon hides a lot of the model details; I'm working on a solution for this at the moment but it is complicated. Instead I will build the forecast in tensorflow like I did with my most recent attempt to improve my [Mariah Carey predictions](/anvil/all-i-want-for-christmas-is-overfitting/).\n", "\n", "For the training data I will use clicks and spend data from the [Google Analytics demo account](https://support.google.com/analytics/answer/6367342). This has the advantage of being public data from a real life Google Ads account. But it has some major disadvantages too as we shall see. If you can give me some data that I can anonymise and make public for use in future demos then I will give you a reduced rate for running the kind of analysis you see in this post; email [fergie@forecastforge.com](mailto:fergie@forecastforge.com) if you are interested in this.\n", "\n", "Start by importing some libraries and loading the data" ] }, { "cell_type": "code", "execution_count": 1, "id": "1d95fb00", "metadata": { "scrolled": true }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "2021-12-09 12:15:01.609375: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcudart.so.11.0'; dlerror: libcudart.so.11.0: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /nix/store/bz317974raly88wakps7h1y7p9l81hgz-gcc-10.3.0-lib/lib:\n", "2021-12-09 12:15:01.609411: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.\n" ] }, { "data": { "text/html": [ "
\n", " | Day | \n", "Clicks | \n", "Cost | \n", "
---|---|---|---|
0 | \n", "2018-01-01 | \n", "302 | \n", "$122.93 | \n", "
1 | \n", "2018-01-02 | \n", "299 | \n", "$134.97 | \n", "
2 | \n", "2018-01-03 | \n", "332 | \n", "$134.61 | \n", "
3 | \n", "2018-01-04 | \n", "345 | \n", "$128.13 | \n", "
4 | \n", "2018-01-05 | \n", "358 | \n", "$129.13 | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "
1419 | \n", "2021-11-20 | \n", "581 | \n", "$807.64 | \n", "
1420 | \n", "2021-11-21 | \n", "474 | \n", "$746.14 | \n", "
1421 | \n", "2021-11-22 | \n", "518 | \n", "$727.00 | \n", "
1422 | \n", "2021-11-23 | \n", "295 | \n", "$515.11 | \n", "
1423 | \n", "NaN | \n", "249,269 | \n", "$284,602.42 | \n", "
1424 rows × 3 columns
\n", "\n", " | Clicks | \n", "Cost | \n", "
---|---|---|
2020-11-10 | \n", "39.0 | \n", "24.93 | \n", "
2020-11-11 | \n", "165.0 | \n", "158.85 | \n", "
2020-11-12 | \n", "107.0 | \n", "164.09 | \n", "
2020-11-13 | \n", "109.0 | \n", "176.69 | \n", "
2020-11-14 | \n", "97.0 | \n", "330.31 | \n", "
... | \n", "... | \n", "... | \n", "
2021-11-19 | \n", "495.0 | \n", "759.03 | \n", "
2021-11-20 | \n", "581.0 | \n", "807.64 | \n", "
2021-11-21 | \n", "474.0 | \n", "746.14 | \n", "
2021-11-22 | \n", "518.0 | \n", "727.00 | \n", "
2021-11-23 | \n", "295.0 | \n", "515.11 | \n", "
379 rows × 2 columns
\n", "