Site icon crawstat.

Imputing Time Series Missing Values

Today, let’s see how different missing value impute methods stack up for various types of time series. It was inspired by a recent Berlin Time Series Analysis meetup, you can check out the original code here. First, we’ll generate imaginary monthly sales data (from a normal distribution) from January 2010 to November 2020 in 5 different types of series – stationary, changing mean, changing variance, random walk, and seasonal. Next, we’ll generate sales with randomly removed values and fill them. To do so we’ll create a mask to tag missing and filled values, generate random missing values (15%) using the boolean mask to replace those index values with null values, and fill the missing values using the following impute methods:

Lastly, we’ll see how the impute methods performed for each series based on their mean absolute error (MAE). Key findings according to MAE:

It’s important to note that here we generate random missing values to test out how different imputation methods perform in different time series trends. In reality, when data includes missing values, it’s important to understand the context and problem you’re trying to solve, how the data is collected and study design, where the missing data came from (e.g., random, business holidays, non-response, etc.), and how we could expect missing values in the future.

Code with explanatory notes are on our Git and below as a gist.

Exit mobile version