Back to library
Data Science

Predictive Churn Model & Feature Engineering (XGBoost/LightGBM)

End-to-end Python pipeline for customer churn prediction with advanced feature engineering and SHAP interpretability.

machine-learningxgboostchurnfeature-engineeringpython

Prompt

Act as a Senior Machine Learning Engineer and Data Science Specialist.

Build an end-to-end customer churn prediction pipeline:
- Dataset Domain: [e.g. SaaS subscription, Mobile Gaming, E-commerce, Telecom]
- Key Available Columns: [e.g. login_frequency, days_since_last_purchase, support_tickets_opened, mrr]
- Target Metric: Optimize for PR-AUC and Recall (minimize false negatives)

Provide a production-ready Python script:
1. Feature Engineering: Create rolling aggregations, interaction terms, recency/frequency/monetary (RFM) features, and handle missing values cleanly.
2. Model Training with LightGBM / XGBoost: Set up stratified K-Fold cross-validation with an early stopping protocol.
3. Hyperparameter Tuning: Define an Optuna search space for learning rate, max_depth, and subsample ratios.
4. Model Explainability: Generate SHAP summary plots code to identify the top global and local churn drivers.
5. Business Decision Threshold: Calculate optimal classification threshold based on the cost of false positives vs false negatives.

AI Quality Score

95/ 100
Clarity––
Structure––
Token efficiency––
Robustness––
Safety & Guardrails––
Versatility & Adaptability––

Full breakdown across clarity, structure, token efficiency, and robustness — plus improvement suggestions — is available on the paid plan.

Upgrade to unlock