-
Notifications
You must be signed in to change notification settings - Fork 53
feat(examples): Add customer churn prediction ML example #561
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,77 +1,123 @@ | ||
| # Examples | ||
| # Customer Churn Prediction — PDD Example | ||
|
|
||
| This directory contains examples that demonstrate comparisons between using Cursor and Prompt-Driven Development (PDD) for various programming tasks. These examples serve as practical illustrations of how PDD can be used to generate and modify code, via the pdd sync command, and how it compares to traditional development approaches. | ||
| This example demonstrates a complete **Prompt-Driven Development** workflow for a real-world machine learning use case: **predicting customer churn** using logistic regression. | ||
|
|
||
| ## Getting Started | ||
| It is a companion to the core `hello` and `factorial_calculator` examples, showing PDD applied to a **data science / ML context** — a domain not previously covered in the official examples. | ||
|
|
||
| ### Post-Installation Setup (Required first step after installation) | ||
| --- | ||
|
|
||
| Before running any examples, make sure you've completed the PDD setup: | ||
| ## What This Example Covers | ||
|
|
||
| | PDD Concept | Implementation | | ||
| |---|---| | ||
| | Prompt as source of truth | `prompts/customer_churn_python.prompt` | | ||
| | Code generated from prompt | `customer_churn.py` | | ||
| | Usage example | `example_customer_churn.py` | | ||
|
Comment on lines
+11
to
+15
|
||
| | Unit test suite | `test_customer_churn.py` | | ||
|
|
||
| --- | ||
|
|
||
| ## Files | ||
|
|
||
| ``` | ||
| examples/customer_churn/ | ||
| ├── prompts/ | ||
| │ └── customer_churn_python.prompt # PDD prompt (source of truth) | ||
| ├── customer_churn.py # Generated module | ||
| ├── example_customer_churn.py # Runnable demo | ||
|
Comment on lines
+23
to
+27
|
||
| ├── test_customer_churn.py # Unit tests (pytest) | ||
| └── README.md # This file | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| ```bash | ||
| pip install pandas numpy scikit-learn pytest | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## Run the Example | ||
|
|
||
| ```bash | ||
| cd examples/customer_churn | ||
| python example_customer_churn.py | ||
| ``` | ||
|
|
||
| **Expected output:** | ||
| ``` | ||
| ======================================================= | ||
| PDD Example: Customer Churn Prediction | ||
| ======================================================= | ||
|
|
||
| 📦 Generating synthetic customer dataset (100 rows)... | ||
| Dataset shape : (100, 8) | ||
| Churn rate : 27.0% | ||
|
|
||
| 🔧 Training logistic regression pipeline... | ||
|
|
||
| 📊 Model Evaluation (held-out 20% test set): | ||
| Accuracy : 75.00% | ||
| Precision : 60.00% | ||
| Recall : 50.00% | ||
| F1 Score : 54.55% | ||
|
|
||
| 🔍 Top 5 Feature Importances (by abs coefficient): | ||
| num_support_tickets +0.5231 ↑ increases churn | ||
| tenure -0.4812 ↓ decreases churn | ||
| contract_type_Month-to-month +0.3901 ↑ increases churn | ||
| ... | ||
|
|
||
| 🎯 Individual Customer Predictions: | ||
|
|
||
| High-risk customer (month-to-month, 2 months tenure): | ||
| → Churn probability: 68.42% 🔴 | ||
|
|
||
| Low-risk customer (2-year contract, 58 months tenure): | ||
| → Churn probability: 18.75% 🟢 | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## Run the Tests | ||
|
|
||
| ```bash | ||
| cd examples/customer_churn | ||
| pytest test_customer_churn.py -v | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## Run with PDD | ||
|
|
||
| To regenerate the code from the prompt using PDD: | ||
|
|
||
| ```bash | ||
| pdd setup | ||
| # From the repo root | ||
| pdd --force sync customer_churn | ||
| ``` | ||
|
|
||
| This command will guide you through: | ||
| - Installing shell tab completion | ||
| - Capturing your API keys | ||
| - Creating ~/.pdd configuration files | ||
| - Writing the starter prompt | ||
| To implement improvements from a GitHub issue: | ||
|
|
||
| After setup, reload your shell: | ||
| ```bash | ||
| source ~/.zshrc # or source ~/.bashrc / fish equivalent | ||
| pdd change https://github.com/promptdriven/pdd/issues/<issue-number> | ||
| ``` | ||
|
|
||
| ## Available Examples | ||
|
|
||
| ### Agentic Fallback | ||
| The agentic fallback example demonstrates using agentic fallback to resolve cross-file dependencies during automated debugging. | ||
| The example has two files — `src/main.py` and `src/utils.py` — where `main.py` fails without reading `utils.py`. | ||
| With agentic fallback enabled, the CLI agent (Claude/Gemini/Codex) can read `utils.py`, understand the dependency, and fix `main.py`. | ||
| Users may intentionally introduce errors in `src/utils.py` to test the agentic fix functionality. | ||
|
|
||
| Additional examples demonstrating the use of agentic fallback are provided for Java, TypeScript, and JavaScript. | ||
|
|
||
| ### Edit File Tool | ||
| The edit_file_tool_example walks through generating a complete Python tool using PDD's streamlined `pdd --force sync` workflow. This example shows: | ||
| - How to drive end-to-end project generation (code, tests, docs) from component prompts (complete dev units) | ||
| - Using the provided Makefile targets to orchestrate setup, prompt creation, and sync runs | ||
| - Integrating automation features like command logging and optional cost tracking during sync | ||
|
|
||
| ### Handpaint | ||
| The handpaint example demonstrates how PDD can be used to create and modify a painting application. This example shows: | ||
| - How PDD can be used to generate code for a graphical application | ||
| - The process of iteratively refining code through PDD | ||
| - A comparison between traditional development and PDD-assisted development | ||
|
|
||
| ### Hello World | ||
| The hello_world example demonstrates how PDD can be used to generate code for a simple Python function that prints "hello". This example shows: | ||
| - How PDD can be used to generate code for a simple Python function via the sync command | ||
|
|
||
| ### Hello You | ||
| The hello_you example expands on the Hello World flow by rendering a personalized greeting in large ASCII art. This example shows: | ||
| - Capturing the current shell username (via `whoami`) and feeding it into the generated program | ||
| - Building a reusable ASCII art alphabet map inside the generated Python file to spell arbitrary strings | ||
| - Producing a self-contained script that prints a 10-row tall "Hello <username>" banner with no external dependencies | ||
|
|
||
| ### Pi Calc | ||
| The pi_calc example demonstrates how PDD can be used to generate code for a simple Python function that calculates the value of Pi. This example shows: | ||
| - How PDD can be used to generate code for a simple Python function using the sync command | ||
|
|
||
| ### QR Code Sandwich | ||
| The qrcode_sandwich example demonstrates how PDD can be used to generate code that produces scannable QR codes embedded within photorealistic images using ControlNet QR conditioning. This example shows: | ||
| - Creating a QR code that blends into a realistic image while remaining scannable | ||
| - Leveraging ControlNet QR conditioning in a generated Python script | ||
| - Iterating with PDD to refine parameters and results | ||
|
|
||
| More examples will be added to this directory as they are developed. | ||
|
|
||
| ## Purpose | ||
| These examples are designed to help developers understand: | ||
| 1. The capabilities of PDD in different programming contexts | ||
| 2. How PDD compares to traditional development workflows | ||
| 3. Best practices for using PDD effectively | ||
| 4. Real-world applications of PDD in various domains | ||
|
|
||
| Each example includes documentation and code that can be used as a reference for your own PDD-based development projects. | ||
| --- | ||
|
|
||
| ## About This Example | ||
|
|
||
| This example was contributed as part of a pull request to expand PDD's example library into the **machine learning / data science** domain. The prompt covers: | ||
|
|
||
| - **sklearn Pipeline** with `ColumnTransformer` for mixed-type preprocessing | ||
| - **Logistic Regression** binary classification | ||
| - **Evaluation metrics**: accuracy, precision, recall, F1 | ||
| - **Edge case handling**: missing values, empty inputs, None model | ||
|
|
||
| It demonstrates that PDD's prompt-first approach scales naturally to ML workflows, where prompt clarity directly impacts the quality and reproducibility of generated model code. | ||
|
|
||
| --- | ||
|
|
||
| *Contributed by [Darius Rowser](https://github.com/Drowser2430)* | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,165 @@ | ||||||
| """ | ||||||
| Customer Churn Prediction Module | ||||||
| Generated via PDD (Prompt-Driven Development) workflow. | ||||||
| Prompt: prompts/customer_churn_python.prompt | ||||||
|
||||||
| Prompt: prompts/customer_churn_python.prompt | |
| Prompt: examples/customer_churn_python.prompt |
Copilot
AI
Feb 24, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OneHotEncoder(..., sparse_output=False) requires scikit-learn >= 1.2; the README currently installs scikit-learn without a minimum version. Either document the minimum required scikit-learn version for this example or use an encoder argument compatible with older versions to avoid runtime failures for users.
| ("onehot", OneHotEncoder(handle_unknown="ignore", sparse_output=False)) | |
| ("onehot", OneHotEncoder(handle_unknown="ignore", sparse=False)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
examples/README.mdhas been replaced with churn-specific documentation, which removes the overview/index for all other example projects underexamples/. Please restore the examples index README and move the churn docs into a dedicatedexamples/customer_churn/README.md(then link to it from the main examples README).