File size: 1,573 Bytes
c94dda2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b07b05a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# 🧠 TabTransformer Multitask Model for Churn, Tenure, and LTV Prediction

This model is a multitask `TabTransformer` implemented in PyTorch, designed to perform:

- **Binary classification** for customer **churn**
- **Regression** for customer **tenure**
- **Regression** for customer **LTV (Lifetime Value)**

It is saved as a pickle file: `model.pkl` and includes all custom layers (e.g., positional encoding).

---

## 🧩 Model Architecture

- Tabular input with:
  - `x_num`: Numerical features (projected into latent space)
  - `x_cat`: Categorical features (embedded + transformer)
- Transformer-based attention over categorical embeddings
- Multi-head output for multitask predictions:
  - `Churn`: Sigmoid activation for binary classification
  - `Tenure` and `LTV`: Linear regression heads

---

## 🧪 How to Use

### 1. Install Dependencies

```bash
pip install torch pandas


import torch

# Load the model from pickle
with open("model.pkl", "rb") as f:
    model = torch.load(f)

model.eval()


# Example dummy input
x_num = torch.rand((1, 10))          # Replace 10 with your actual num_features
x_cat = torch.randint(0, 5, (1, 3))  # Replace with your actual number of categories

# Predict
churn_prob, predicted_tenure, predicted_ltv = model(x_num, x_cat)

print("Churn probability:", churn_prob.item())
print("Predicted tenure:", predicted_tenure.item())
print("Predicted LTV:", predicted_ltv.item())


(
    churn_prob: FloatTensor of shape (B, 1),
    predicted_tenure: FloatTensor of shape (B, 1),
    predicted_ltv: FloatTensor of shape (B, 1)
)