# Customer Churn Prediction in B2B Non-Contractual Business Settings Using Invoice Data
## 3 Materials and Methods
### Features, Training, and Test Sets  
To construct features from the available data, we adopt a multi-slicing approach proposed by [18] as a foundation, which we build upon by introducing what we refer to as Cumulative Features (_CF_) and Delta Features (_DF_). This approach is illustrated in Figure 2. To create the training set, for every forecast origin \(t\) (which occurs at the end of the observed month and is offset \(K\)-times by one month for the length of the time period that the training data spans), we derive two sets of features:  
* _CF_, which comprise features constructed using all the data available in the time period between the date of the first available record (available data origin) and the date of forecast origin \(t\);
* _DF_, which comprise features constructed using monthly data for \(n\) number of non-overlapping monthly periods prior to the forecast origin \(t\), such that \(m_{t}>m_{t-1}>m_{t-n}\). These features are derived and merged at the customer level for customers who were active in the latest month relative to the forecast origin \(t\) (i.e., \(m_{t}\)). Then, all vectors comprising merged customer-level features at different forecast origins \(t\) (that is, for customers active in \(\{C(t_{1}^{train}),C(t_{K-1}^{train}),\ldots,C(t_{K}^{train})\}\) periods) are stacked in a feature matrix \(X_{train}\). Similarly, to create labels, for each active customer at a forecast origin \(t\), we observe whether they had made purchases in any of the subsequent months reflecting different churn definitions (\"Label window \(v\)\", spanning \(t+v\) months for \(v\in[1,2,3]\)) and if so, we designate them as non-churners (i.e., they are labeled \"0\"). Otherwise, we label them as churners (they are assigned label \"1\"). In that way, we obtain a label vector \(y_{train}\) that we combine with the feature matrix \(X_{train}\) to construct the final training set. Figure 1: Monthly chum rates given different churn definitions (three, two and one month). Figure 2: Deriving training and test sets by using the multi-slicing approach and delta features (illustrated for \(v=3\) and \(DF\) length of \(n=3\)). We rely on the out-of-period testing approach to assess predictive performance of models we devise, which has been argued to produce more realistic estimates than the more commonly used out-of-sample testing approach when there might be temporal changes in the factors driving churn and market conditions in general [18; 41]. Within this approach, a portion of the data coming from a period more recent than the training data is used to evaluate model performance, which more closely resembles conditions encountered when making future predictions in real-world settings. This is illustrated in the lower part of Figure 2, where the features and labels for the test set are derived for customers in \(\mathbb{C}(t^{test})\), such that the origin of forecast \(t^{test}=t^{train}+v\). As mentioned earlier, we use exclusively features that can be derived from invoice data alone. To illustrate, within \(CF\), we calculate the total and average amounts spent per purchase and per distinct products, number of purchases, and those of particular products, as well as the number of days since the latest purchase relative to the forecast origin \(t\), as some of the features. In terms of \(DF\), we derive these values as well as their differences between the latest month \(m_{t}\) and each preceding month \(m_{t-n}\) for \(n\in\{-1,\ldots-DF_{num}\}\), where \(DF_{num}\) is the length of the observation period for \(DF\) in months. We use \(DF_{num}\) values of \([1,3,6,9,12]\), which correspond to time periods usually used for comparisons in business settings (i.e., last month, last quarter, two previous quarters, three previous quarters, and last year). This way, we are able to explicitly quantify changes in purchasing patterns of customers between the latest observation period and previous periods, as well as to capture seasonality in their behavior.