# How to transform time series data to apply supervised learning algorithms to it?

Apologies in advance for what may be a very basic question.

I have a dataset consisting of marketing calls to different clients, which include the timestamp for the call. My goal is to train a model to predict if whether a customer will answer a call or ignore it based on the call time, as well as other features like caller id, etc.

The issue is that the outcome of the call is clearly time dependent, that is, the order of the data points per client matters for the prediction of the dependent variable at a given time.

My question is, how can I transform my features, so that I can use standard classification algorithms like Logistic Regression/Random Forest to classify a new data point? Are these algorithms effective for these scenarios? If so, how should I proceed to take the previous data points into consideration?

I have read that time series data can be converted to a supervised learning problem, by including lead and lag columns of the dependent variable. But since my test data will not have those columns, I am confused to how they might help me.

Thank you very much.

You can aggregate all previous data points into a new features. For example the number of previous (un)successful call attempts or the number of days since the last call. After this aggregation (of transforming previous calls into new scalar features) you are no longer dealing with a time series but have the usual design matrix with one row per client (and one column per feature).

Are these algorithms effective for these scenarios?

They should be effective if you can derive good features, which shouldn't be too difficult. This is more manual than using a sequence-model (say LSTM) but if you derive good features, I would expect this too work better.

I have read that time series data can be converted to a supervised learning problem, by including lead and lag columns of the dependent variable. But since my test data will not have those columns, I am confused to how they might help me.

It doesn't sounds like you are dealing with a standard time-series problem. The timestamps themselves don't strike me as too important for predicting answers to a call. You can probably achieve good results by simply including the time of day and day of the week in addition to the features mentioned above.

• Thank you very much for your answer. Aggregating all previous data points into new features makes a lot of sense, but I have one question: when you said " For example the number of previous (un)successful call attempts", in this case, this feature can only be derived for the training data, in which I know the outcomes for all data points. But for test data, this column would always be empty, and thus would not be meaningfull. Am I correct? Jul 8 '19 at 20:38
• why don't you have that data for the test data? you can transform the entire dataset before splitting in training and test data (be careful not to split by client across training and test data if you have multiple datapoints per client)
– oW_
Jul 8 '19 at 20:55

You need to transform your timestamp column into several numerical/categorical columns representing that specific timestamp. After converting that timestamp column into features, you can simply throw supervised algorithms on the problem.

You could leverage for example the fast.ai function add_datepart that you can find here: