{ "cells": [ { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "# Example Interrupted Time Series (ITS) with sci-kit learn models\n", "\n", "This notebook shows an example of using interrupted time series, where we do not have untreated control units of a similar nature to the treated unit and we just have a single time series of observations and the predictor variables are simply time and month." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "from sklearn.linear_model import LinearRegression\n", "\n", "import causalpy as cp" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "%config InlineBackend.figure_format = 'retina'" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## Load data" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | month | \n", "year | \n", "t | \n", "y | \n", "
---|---|---|---|---|
date | \n", "\n", " | \n", " | \n", " | \n", " |
2010-01-31 | \n", "1 | \n", "2010 | \n", "0 | \n", "25.058186 | \n", "
2010-02-28 | \n", "2 | \n", "2010 | \n", "1 | \n", "27.189812 | \n", "
2010-03-31 | \n", "3 | \n", "2010 | \n", "2 | \n", "26.487551 | \n", "
2010-04-30 | \n", "4 | \n", "2010 | \n", "3 | \n", "31.241716 | \n", "
2010-05-31 | \n", "5 | \n", "2010 | \n", "4 | \n", "40.753973 | \n", "