| # 🧠 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) |
| ) |
| |