customer-churn-prediction / src /recommendation_engine.py
Moaaz2os's picture
Upload 4 files
d1d5e45 verified
Raw
History Blame Contribute Delete
3.11 kB
def get_recommendations(input_dict: dict, probability: float) -> list:
"""Generate retention recommendations based on the 5 key features."""
recs = []
service_calls = int(input_dict.get("Customer Service Calls", 0))
monthly = float(input_dict.get("Monthly Charge", 0))
contract = str(input_dict.get("Contract Type", "Month-to-Month"))
account_len = int(input_dict.get("Account Length", 0))
gb_download = float(input_dict.get("Avg Monthly GB Download", 0))
# Critical risk β€” immediate action
if probability >= 0.75:
recs.append((
"🎯", "Launch Immediate Retention Campaign",
"Customer is at critical risk. Assign a dedicated account manager "
"and offer a personalized retention package within 24 hours."
))
# High service calls β€” #1 churn driver
if service_calls >= 4:
recs.append((
"πŸ“ž", "Resolve Service Issues Urgently",
f"{service_calls} service calls detected β€” the top churn predictor. "
"Escalate to senior support, identify root cause, and follow up proactively."
))
elif service_calls >= 2:
recs.append((
"πŸ› ", "Proactive Support Check-in",
"Schedule a satisfaction call to address any unresolved issues "
"before they escalate further."
))
# High monthly charge
if monthly > 90:
recs.append((
"πŸ’°", "Review & Optimize Pricing Plan",
f"Monthly charge of ${monthly:.0f} is above average. "
"Offer a bundled plan or loyalty discount to reduce cost by 15-20%."
))
# Month-to-Month contract
if contract in ["Month-to-Month", "0", 0]:
recs.append((
"πŸ“‹", "Offer Annual Contract Upgrade",
"Month-to-Month customers churn 3x more. "
"Offer a 20% discount to switch to a 1 or 2-year contract."
))
# New customer
if account_len <= 12:
recs.append((
"πŸš€", "New Customer Onboarding Program",
f"Only {account_len} months as a customer. "
"Assign an onboarding specialist and schedule a 30-day satisfaction check-in."
))
# High data usage β€” valuable customer
if gb_download > 40:
recs.append((
"πŸ“‘", "Offer Premium Data Plan Upgrade",
f"Averaging {gb_download:.0f} GB/month β€” a high-value power user. "
"Offer an unlimited data plan with priority network access."
))
# Low usage β€” engagement risk
elif gb_download < 10 and probability > 0.4:
recs.append((
"πŸ“Š", "Re-engage Low Usage Customer",
"Low data usage may indicate disengagement. "
"Offer free data credits or a plan downgrade to retain the customer."
))
if not recs:
recs.append((
"βœ…", "Customer in Good Standing",
"No immediate action required. "
"Monitor quarterly and consider a loyalty reward to strengthen retention."
))
return recs