Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Convert Non-Stationary Data to Stationary | Non-Stationary Models
course content

Course Content

Time Series Analysis

Convert Non-Stationary Data to StationaryConvert Non-Stationary Data to Stationary

So, let's move on to the stage of processing non-stationary data. You have already seen predictive models that you can use to work with stationary data, but since most data is non-stationary, there are ways to convert it.

There are many types of transformations, such as difference, logarithmic transformation, proportional change, etc. But the main idea of mathematical transformations is to apply some function for each value of the time series to remove the time dependence (this includes trends and seasonality).

We will start with the differencing used in the ARIMA model. The principle is simple - the past value is subtracted from the current one:

This allows you to stabilize the value of the time series, making it more constant. Let's implement the difference transformation using Python:

Let's move on to the logarithmic transformation. If the difference allows us to equalize the mean, then the logarithmic transformation stabilizes the time series variance. The only limitation is that the logarithmic transformation can only work with positive values.

Below is the code for logarithmic transformation (log transformation):

Task

Implement a difference transformation on the AirPassengers.csv dataset and output the average before and after for the #Passengers column.

  1. Read the AirPassengers.csv file.
  2. Drop the "Month" column out of the df DataFrame.
  3. Calculate the mean value of the "#Passengers" column before changes.
  4. Calculate the differences of each value of the column"#Passengers" compared with the previous (periods = 1`), drop NA values, and calculate the mean for the updated column.

Everything was clear?

Section 5. Chapter 2
toggle bottom row
course content

Course Content

Time Series Analysis

Convert Non-Stationary Data to StationaryConvert Non-Stationary Data to Stationary

So, let's move on to the stage of processing non-stationary data. You have already seen predictive models that you can use to work with stationary data, but since most data is non-stationary, there are ways to convert it.

There are many types of transformations, such as difference, logarithmic transformation, proportional change, etc. But the main idea of mathematical transformations is to apply some function for each value of the time series to remove the time dependence (this includes trends and seasonality).

We will start with the differencing used in the ARIMA model. The principle is simple - the past value is subtracted from the current one:

This allows you to stabilize the value of the time series, making it more constant. Let's implement the difference transformation using Python:

Let's move on to the logarithmic transformation. If the difference allows us to equalize the mean, then the logarithmic transformation stabilizes the time series variance. The only limitation is that the logarithmic transformation can only work with positive values.

Below is the code for logarithmic transformation (log transformation):

Task

Implement a difference transformation on the AirPassengers.csv dataset and output the average before and after for the #Passengers column.

  1. Read the AirPassengers.csv file.
  2. Drop the "Month" column out of the df DataFrame.
  3. Calculate the mean value of the "#Passengers" column before changes.
  4. Calculate the differences of each value of the column"#Passengers" compared with the previous (periods = 1`), drop NA values, and calculate the mean for the updated column.

Everything was clear?

Section 5. Chapter 2
toggle bottom row
some-alt