How do we build a vectorized customer churn risk scoring pipeline combining spend and tenure features?
A vectorized scoring pipeline using a multi-feature Pandas UDF to predict customer churn probability at scale.
Batch ML inference pipelines scoring hundreds of millions of customer profiles daily.
import pandas as pd
from pyspark.sql.functions import col, pandas_udf
@pandas_udf("double")
def predict_churn_risk(spend: pd.Series, tenure: pd.Series) -> pd.Series:
return 1.0 / (1.0 + (spend * 0.001) + (tenure * 0.05))
scored_df = customer_features.withColumn(
"churn_risk_score",
predict_churn_risk(col("annual_spend"), col("tenure_months"))
)Practice typing production-grade PySpark code for Production Vectorized Machine Learning Scoring Pipeline.