Skip to content

Commit 83e807b

Browse files
committed
customer churn prep
1 parent c56a2a4 commit 83e807b

8 files changed

+15
-9
lines changed

temp/customer_churn_ai_ml/customer_churn_ai_ml.py 002_customer_churn_ai_ml/customer_churn_ai_ml.py

+15-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1+
# BUSINESS SCIENCE GENERATIVE AI/ML TIPS ----
2+
# AI-TIP 002 | AI/ML FOR CUSTOMER CHURN ----
13

2-
4+
# GOALS:
5+
# - Use LLMs to generate summaries of customer tickets
6+
# - Use Text Embeddings to convert text to vectors
7+
# - Use XGBoost to predict customer churn with AI features
38

49
# Libraries
510

@@ -18,12 +23,13 @@
1823
import ast
1924
import matplotlib.pyplot as plt
2025

21-
22-
2326
# ---------------------------
2427
# 1. Setup
2528
# ---------------------------
2629

30+
# PATHS
31+
PATH_ROOT = "002_customer_churn_ai_ml/"
32+
2733
# MODELS
2834
LLM_MODEL = "gpt-4o-mini"
2935
EMBEDDING_MODEL = "text-embedding-ada-002"
@@ -35,7 +41,7 @@
3541
client = OpenAI(api_key=os.environ['OPENAI_API_KEY'])
3642

3743
# DATASET
38-
df = pd.read_csv("temp/customer_churn_ai_ml/data/customer_churn.csv")
44+
df = pd.read_csv(PATH_ROOT + "/data/customer_churn.csv")
3945

4046
# ---------------------------
4147
# 2. Generate Summaries with an LLM
@@ -46,7 +52,7 @@
4652
def summarize_ticket(ticket_text):
4753
prompt = f"Summarize the following customer ticket focusing on the main complaint or request:\n\n{ticket_text}\n\nSummary:"
4854
response = client.chat.completions.create(
49-
model="gpt-4o-mini",
55+
model=LLM_MODEL,
5056
messages=[
5157
{"role": "system", "content": "You are a helpful assistant."},
5258
{"role": "user", "content": prompt}
@@ -58,9 +64,9 @@ def summarize_ticket(ticket_text):
5864

5965
df['ticket_summary'] = df['ticket_notes'].apply(summarize_ticket)
6066

61-
# df.to_csv("temp/customer_churn_ai_ml/data/customer_churn_summary.csv", index=False)
67+
# df.to_csv(PATH_ROOT + "/data/customer_churn_summary.csv", index=False)
6268

63-
df = pd.read_csv("temp/customer_churn_ai_ml/data/customer_churn_summary.csv")
69+
df = pd.read_csv( PATH_ROOT + "/data/customer_churn_summary.csv")
6470
df
6571

6672
# ---------------------------
@@ -80,9 +86,9 @@ def get_embeddings(text):
8086

8187
df['summary_embedding'] = df['ticket_summary'].apply(get_embeddings)
8288

83-
# df.to_csv("temp/customer_churn_ai_ml/data/customer_churn_summary_embeddings.csv", index=False)
89+
# df.to_csv(PATH_ROOT + "/data/customer_churn_summary_embeddings.csv", index=False)
8490

85-
df = pd.read_csv("temp/customer_churn_ai_ml/data/customer_churn_summary_embeddings.csv")
91+
df = pd.read_csv(PATH_ROOT + "/data/customer_churn_summary_embeddings.csv")
8692

8793
df
8894

0 commit comments

Comments
 (0)