I know that the predictive horizon is the time window that runs from the observation of the data to the manifestation of the target variable.

But how can I deal with prediction if the time horizon varies in my dataset? I mean, how can I manage the prediction when the target variable is observed at a (known) variable time horizon with respect to the data?

Is it possible to train a simple logistic reression with the aim of having a 1 year prediction starting from a training dataset where the predictive horizon is varying (but known).

Here you have an example:

  • target is the target variable to be predicted
  • X1, X2 are the features
  • time is the time (in months) elapsed between the observation of the features and the target variable (i.e. the time horizon)

My aim is to use this dataset (below is just an example) to predict the target variable over a predictive horizon of 1 month

target X1 X2 time
0 0,42 0,23 3
0 0,43 0,14 4
0 0,27 0,16 6
1 0,05 1,41 2
1 0,59 1,10 3
0 0,31 0,47 5
0 0,14 0,32 3
1 0,71 0,68 4

Thank you

  • 2
    $\begingroup$ Please post a sample table perhaps, with a series of dates that better illustrate your question. That may help. $\endgroup$ Sep 5, 2023 at 19:39
  • $\begingroup$ Done, I hope it will help. Thank you $\endgroup$ Sep 7, 2023 at 6:35

1 Answer 1


My understanding of your sample data is that you have X1, X2 as predictors, and two things you want to predict: whether target will be 0 or 1, and how many months before that result happens.

So, one approach is to train two models. One to predict how long before you get a result, and one to predict what that result will be.

Note: "target" would not be used as a predictor in the model predicting "months", and "months" would not be used in the model predicting "target", as you don't know either in advance. Each model only uses the same X predictors.

You left your question very abstract, so a real-world example would be sales contracts for a company. You have various X predictors, such as size of company, size of contract, expected profit margin, what type of service/product is being negotiated, etc. And sometimes these contracts take 1 month to be decided and negotiated, and sometimes they take 10 months. E.g. The bigger the company the longer they take to decide. And at the end of that decision period, you get the contract, or someone else does. E.g. the better the profit margin the more competitive bids, so the less chance of you getting it.

UPDATE BASED ON Q IN COMMENT The glib answer is that based on your example data the probability of having the outcome 1 within a month is 0.0, as it has never been seen. No need to train a model.

Anyway, one way to use two models together is run both. If it predicts a result of 1 AND predicts a time span of less than or equal to one month, that is a 1.0, and anything else is a 0.0.

If the models give you probabilities as well then you could multiply the result from each model, to get a probability. E.g. if it says probability of a 1 is 0.6, 0 is 0.4, and probability of 1 month is 0.4, probability of 2 months is 0.3, and sum of probs of all longer periods is the other 0.3, then the probability of a 1 within one month is 0.6 * 0.4 = 0.24.

The other approach, if that is all you care about, is to modify your training data. Remove both the target and time columns, and add a new target column that is 1 when target=1 AND time <= 1 month and 0 for all other rows.

Then train a single model on that.

  • $\begingroup$ Thank you @Darren Cook, you're saying I need to train two models (e.g two logistic regressions). What if the two models are correlated? Is there a way to take into account this issue? $\endgroup$ Sep 14, 2023 at 14:00
  • $\begingroup$ @MarcoBallerini I think it is fine - if they are correlated it means the data is correlated. E.g. the higher months gets the less chance of result being a 1. I did just update my answer to clarify that only X1,X2 are used in each model. You can't use months to help predict target as you don't know it in advance. $\endgroup$ Sep 14, 2023 at 14:18
  • $\begingroup$ Thank you again @Darren Cook, I’m sorry for my late reply but I’m still thinking of the problem. So, after I’ve trained my two models, let’s say P1 predicts what the result will be and P2 predicts how long we have to wait the result, how can I use them to have a single number telling me the probability of having the outcome 1 within a month? $\endgroup$ Sep 27, 2023 at 8:04
  • $\begingroup$ @Marco See updated answer. $\endgroup$ Oct 2, 2023 at 20:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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