Marketing Mix Modeling: Mean Centric Data Transformation Using Python

Ghanshyam Savaliya
2 min readDec 5, 2022

--

In this article, we will be going to focus on the data transformation before inputting any data into the regression model.

What is Mean Centric data Transformation?

Mean Centric data transformation means calculating absolute deviation for each Geography, Product and time period value with their Mean value. This denotes that each column will be transformed in such a way that the resulting variable will have a zero mean.

In the below example, we have Monthly price available for a specific year.

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

# Read data from CSV files and created Pandas dataframe
df = pd.read_csv("price.csv")

# Plot the pandas Dataframe to the line Chart
df.plot.line()

Now If we want to transform the above variable before inputting data into the regression model then we can try to utilize following code to generate transformed variable through python.

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

# Read data from CSV files and created Pandas dataframe
df = pd.read_csv("price.csv")

# Transformation of Price varaible to mean centric
df["Price"] = df.Price - df.Price.mean()

# Plot the pandas Dataframe to the line Chart
df.plot.line()

Even after change in Y-Axis values, there are no change in Month over Month movement (Directional movement) as well correlation with Dependent variable, hence we are just changing magnitude of the variable.

If we want to compare both the chart then it will look like below:

As per the above chart, there are 100% correlation between both variables (Original data Vs Mean Centered data). There are just change in data scale as we had reduced mean value from one Variable.

Once we subtracted the mean from a variable, then necessarily at least one value is now negative and logarithms can’t be calculated (Except some customized complex analysis).

Keep in touch with Ghanshyam Savaliya for more such articles related to Marketing Mix Modeling.

--

--

Ghanshyam Savaliya

I am working as Technical Manager at Tata Consultancy Services for A&I and Marketing Mix Modeling.