Skip to main content
PYSPARK • LESSON 160

Production Vectorized Machine Learning Scoring Pipeline

How do we build a vectorized customer churn risk scoring pipeline combining spend and tenure features?

Expert3 Minutes950 XP
🤔 THE QUESTION

How do we build a vectorized customer churn risk scoring pipeline combining spend and tenure features?

💡 WHAT IS IT?

A vectorized scoring pipeline using a multi-feature Pandas UDF to predict customer churn probability at scale.

🎯 WHAT IS IT USED FOR?

Batch ML inference pipelines scoring hundreds of millions of customer profiles daily.

💻 EXAMPLE
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"))
)

🎯 Mission Objectives

Practice typing production-grade PySpark code for Production Vectorized Machine Learning Scoring Pipeline.

  • Define multi-column vectorized Pandas UDF
  • Vectorize mathematical scoring equation
  • Apply vectorized ML model at scale