Let's say I'm trying to build a time series model with the following dataset:

import pandas as pd
import numpy as np

dates = pd.date_range(start='2020-01-01', end='2021-12-01', freq='MS')
df = pd.DataFrame(np.random.uniform(-1, 1, size=(24, 4)), index=dates, columns=['A_values', 'B_values', 'C_values', 'target'])


            A_values  B_values  C_values    target
2020-01-01  0.211957  0.466739 -0.722106 -0.374654
2020-02-01  0.994487 -0.743675 -0.642014  0.505851
2020-03-01  0.324321  0.568620 -0.806211 -0.882857
2021-10-01  0.940398 -0.168986 -0.339022  0.933428
2021-11-01  0.651798 -0.389200  0.646556  0.113821
2021-12-01  0.437002  0.759874 -0.007980  0.024173

Suppose I will use A_values (which is actual values of a variable), B_values (which is month over month percent change of a variable), C_values (which is year over year percent change of a variable) to forecast target column (which is year over year percent change of one variable).

Now my question is should I convert A_values and B_values to year over year percent change to coordinate with the target column's type? If I don't do that, will it lower the prediction accuracy?

In other words, could the machine learning algorithm such as XGBoost capture the relationship between MoM pct change and YoY pct change?

Note: it's easy to convert the actual value to YoY pct change, meanwhile we lose accuracy as converting from MoM to YoY.


1 Answer 1


I do not think that there is a clear answer without looking at the specific data. But if you want to build a time-series model using linear regression methods, I suggest to try build some features that capture some seasonality like year and month encoding (maybe using a dict saying: 'January':1, 'February':2, .... and for year: '2020':0, '2021':1, ....).

On top of this if you think there is an autoregressive process happening I would add lagged values of your ts. Thus adding values from past months helps the model to understand how the value for the next month will be. Effectively the model will just give coefficients (at least if you think of a linear regression using OLS) to previous values (maybe saying last month has a higher weight than the month before, etc.).

To see how many lags you should include you can check serial auto-correlation plots. But it would make sense to try some values and tread the lagged values as a kind of hyperparameter you want to optimise. Meaning, pick that many lagged values, that result in best model performance.

But check if your time-series is stationary. If not, then you would need to remove the trend to get reliable forecasts.

And also on your core question if you should create some features for MoM and YoY changes, I would suggest to try and see how your model performs with and without that information. As always the goal is to have a model with as little features as possible that generalises well.

I hope that helps a little bit


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.