# ChurnKB: A Generative AI-Enriched Knowledge Base for Customer Churn Feature Engineering
## 3 Method
### Developing a Customer ChurnKB
#### 3.1.7 Developing a Sub-Instance Score Calculator API  
In the final step, several APIs are developed, each corresponding to a sub-instance in the customer churn taxonomy. These APIs employ ML algorithms to calculate sub-instance scores (e.g., an anger score) by analysing the customer's chat logs (i.e., textual input data).  
Figure 2: A snapshot of some of the phrasal/lexical sources linked to the ChurnKB sub-instances. Each of the columns of the Excel file acts as a category related to one of the churn sub-instances.  
The resulting scores, represented as cosine similarity values, form a key component of our proposed ChurnKB, facilitating automated knowledge-based analysis. Algorithm 1 outlines the process of calculating sub-instance scores for APIs using NLP and text mining techniques such as TF-IDF, regular expressions, word tokenization, and stemming. The input for this process is curated textual data, with details of the curation process provided in Section 3.2.  
```
Input: Curated input textual data Output: Calculated sub-instance scores The ChurnKB sub-instance; Linked sub-instance-related lexicons; for Each sub-instance in the ChurnKB do  Reading the curated input textual data;  Reading the linked lexicon;  Applying proper text mining techniques (e.g., Cosine Similarity Calculation); endfor
```  
**Algorithm 1** The process of sub-instance score calculation in APIs that work based on textual data mining techniques.  
We employ term frequency-inverse document frequency (TFIDF) and cosine similarity to quantify textual features related to customer churn. TF-IDF identifies key terms in customer interactions, while cosine similarity measures textual similarity between customer-generated content and churn-related lexicons. These methods allow us to capture churn signals efficiently without requiring extensive domain-specific rules.  
In the realm of text classification, it serves to quantify the similarity between two documents. The range of values spans from 0 to 1, with 0 denoting no similarity and 1 signifying identical documents. For a pair of documents, such as \"doc1\" and \"doc2\", the similarity is expressed through the following formula:  
\[\text{Cosine Sim}(\text{doc1},\text{doc2})=\frac{\text{doc1}\cdot\text{ doc2}}{||\text{doc1}||\times||\text{doc2}||} \tag{1}\]  
which is equal to:  
\[\frac{\sum\limits_{i=1}^{n}A_{i}B_{i}}{\sqrt{\sum\limits_{i=1}^{n}A_{i}^{2} \times\sqrt{\sum\limits_{i=1}^{n}B_{i}^{2}}}} \tag{2}\]  
where \(A_{i}\) and \(B_{i}\) represent the components of vectors doc1 and doc2, respectively [74]. In this study, doc1 and doc2 correspond to a customer-related document and a lexical/phrasal source document, respectively.  
The final version of the churn taxonomy which is embedded with sub-instance score calculator APIs, is called ChurnKB. Figure 1B illustrates a snapshot of the customer ChurnKB, indicative of a small part of the inter-connected feelings and behaviours of customers at risk of churn. ChurnKB contains different concepts and sub-concepts associated with churn-related feelings and behaviours, instances and sub-instances, and the relationships among them. Experiencing various feelings could end in different behaviours in a customer. In this figure, solid connections mainly indicate relationships between concepts, sub-concepts, and corresponding instances. On the other hand, dotted arrows indicate the connection between the instances and the corresponding sub-instances. Examples of existing relationships in ChurnKB include the following: _poor customer service_ could cause customers to feel _unimportant_, which, in turn, may lead to a _lack of interest_ in the service/product. As a reflection of this _lack of interest_, different changes in customers'behaviour or consumption patterns may arise, such as _decreased frequency of use_, _decreased duration of use_, _decreased spend_, or _decreased purchase frequency_. Additionally, a sense of _unimportance_ could directly contribute to _decreased spend_ or _decreased purchase frequency_.