# Predict average duration of a contract

I would like to predict the average duration of a contract. I have worked with different machine learning models before, especially from Scikit-learn, but this task seems to be somehow different for me.

Let's say a company has a contract in its portfolio that can be terminated on a monthly basis. In this (simplified, I actually have data from about 24 months) example the first month in which customers could start the contract was June 2023. Let's say 1000 customers entered into the contract in this month. Now I have the following example data: After 1 month 50 of those customers cancelled the contract, so there were 950 customers left in July 2023. After 2 months another 200 customers have quit, so there were 750 left. After 3 months another 100 quit, and so on. Similarly, I have data for the start of the contract with different customers in the following months. 1200 contracts were signed with start in July 2023. After one month 30 quit, after 2 months 120 and so on. So to sum it up, I have this structure of sample data:

• Start of contract - Number of contracts starting - Remaining customers in this contract after 1, 2, 3... months

• June 2023 - 1000 - 950, 750, 700, 680, 620, 580, 500, 480 (February 2024)

• July 2023 - 1200 - 1170, 1050, 1000, 950, 920, 840, 750

• August 2023 - ...

• ...

• December 2023 - 1400 - 1300, 1250

• January 2024 - 900 - 860

So, logically, you have one data point less for each additional month. The aim now is to calculate the average contract term for this type of contract. This means that each of the above mentioned series will at some point reach a number of 0 remaining customers. After how many months does this happen on average? Or to put it another way: How long does a customer remain in the contract on average?

I have already read about lifetime analysis, but this does not really seem to fit for this problem, because for no starting month I already know the final state, so there would be a lot of "cencored data", right?

Do you have an approach how to address this problem? Which model might fit for this task? Optimally, I would prefer to work with Python.

Kind regards

This means that each of the above mentioned series will at some point reach a number of 0 remaining customers. After how many months does this happen on average?

From this and the structure of your overall question, I get the impression that you would like to perform survival analysis to determine the point when existing customers churn.

To accomplish this in Python, you could use the pysurvival library. This works by building a survival model that predicts the probability of an event happening at a particular time - in this case, that 100% of customers who sign up in a particular month churn.

The model would allow for comparison of predicted churn to actual churn to determine prediction accuracy.

I am not sure if you are simply working with churn data itself or if you have other features that can be incorporated into the model, but it is worth noting that pysurvival has the ability to incorporate extraneous features into the model as well.

• Thank you very much! Unfortunately I have problems installing Pysurvival under Windows. I have seen that there are alternatives such as scikit-survival or lifelines. But before I get into these, I asked myself whether it is actually the right approach to first try to find out when the time series go to 0. Ultimately, I want to find out how long the average term of the contract type is. So does it make sense to take the step of calculating when the time series become 0, or is there perhaps a more direct approach? Currently, I actually only have the specified data and no other features Feb 21 at 10:50
• Well, when you say "calculating when the time series becomes 0" - it appears to me as though you are simply calculating time to zero across each segment of customers and then simply obtaining an average. This is a simple, yet valid approach. However, if you find that time to zero varies drastically across segments - then you won't necessarily know why except for the possibility that customers who sign up during certain months might be likely to stay longer. Feb 21 at 19:13
• Just to get it right, by "segment of customers" do you mean the number of customers who start the contract in a particular month, for example all those who start in July 2023? Feb 22 at 10:41
• Yes - segmenting customers by the month of starting the contract. Feb 22 at 14:21
• Thank you for the confirmation! However, I'm still not quite sure whether I didn't understand your last message correctly or whether we're talking past each other. So do you still think it makes sense to first calculate the average time with a survival analysis library and then deduce the average contract duration from there? Or is there a more direct way to calculate the average cointract duration based on the given data (if so, which would this be?) Feb 22 at 16:09