Chapter 8 Real-World Patterns: Practical Scenarios
8.1 Introduction
Theory is great. Reality is messier. This chapter shows 5 real scenarios and how to handle them.
8.2 Pattern 1: The “It Works in Dev, Fails in Prod” Problem
8.2.1 The Scenario
You built a model in a notebook. It works beautifully. You deploy it. It fails.
Common causes: - Dev data is different from production data - Python versions differ - Dependencies have different versions - Paths are hardcoded - Random seeds not set
8.2.2 The Solution
Ask Claude for help preparing for production:
I have a model that works in development.
Dev environment:
- Python 3.10
- pandas 2.0
- scikit-learn 1.3
- Data: CSV with 10K rows
Production environment:
- Python 3.9
- Hosted on AWS Lambda
- Data: 1M rows from database
- Must process in < 30 seconds
Help me:
1. Test on production-like data
2. Handle version differences
3. Optimize for speed
4. Add monitoring
5. Create fallback behavior
8.3 Pattern 2: The “Colleague Can’t Understand My Code” Problem
8.3.1 The Scenario
You wrote Python code. Your colleague opens it. They’re confused. This happens all the time in teams.
8.3.2 The Solution
Ask Claude to improve for clarity:
My colleague says this code is hard to understand:
[paste code]
Can you:
1. Add clear variable names
2. Break into smaller functions
3. Add comments explaining the logic
4. Add docstrings with examples
5. Simplify the logic if possible
Make it understandable for a junior data scientist.
8.4 Pattern 3: The “Model Performance Degradation” Problem
8.4.1 The Scenario
Your model works great for 3 months. Then performance drops. Why?
Common causes: - Data distribution shifted - Seasonal effects - New data patterns - Bugs in data pipeline - Model training issues
8.4.2 The Solution
Ask Claude to help diagnose:
My model's accuracy dropped from 92% to 78%.
Setup:
- Built 3 months ago
- Retrained monthly
- Current data: [sample]
- Previous data: [sample]
Can you:
1. Compare the data distributions
2. Show which features changed
3. Suggest what went wrong
4. Recommend fixes
5. Show how to detect this early
What monitoring should I add?
8.5 Pattern 4: The “We Need to Scale This” Problem
8.5.1 The Scenario
Your analysis works on 100K rows. Now you need to handle 100M rows. How?
Common approaches: - Use Spark instead of Pandas - Use databases for filtering - Parallelize computation - Sample data for exploration
8.5.2 The Solution
Ask Claude for scaling strategy:
My analysis currently:
- Processes 100K rows in 5 minutes
- Uses pandas, single machine
- Loads entire dataset into memory
Now I need to handle 100M rows.
Options to consider:
- Spark on cluster
- DuckDB for SQL
- Pandas with chunking
- Cloud processing (BigQuery)
Which is best for:
1. One-time analysis?
2. Daily pipeline?
3. Interactive exploration?
Show example implementation for option [your choice].
8.6 Pattern 5: The “Unclear Requirements” Problem
8.6.2 The Solution
Use Claude to help clarify:
I need to build a dashboard for [domain].
Requirements (unclear):
- "Show the data"
- "Make it easy to understand"
- "Something executives will like"
Who are the users?
- [Describe them]
What decisions will they make?
- [List decisions]
What data is available?
- [List sources]
Can you:
1. Help me ask clarifying questions
2. Define realistic requirements
3. Suggest what metrics matter
4. Show a prototype dashboard
5. Create a checklist for success
8.7 General Approach for Any Situation
When stuck, use this framework:
1. DESCRIBE THE PROBLEM
- What are you trying to do?
- What's not working?
- What have you tried?
2. PROVIDE CONTEXT
- Environment (language, libraries, data size)
- Constraints (time, money, skill level)
- Success criteria (what does "solved" look like?)
3. SHOW EXAMPLES
- Sample data
- Expected output
- Error messages
4. ASK SPECIFICALLY
- "What's the root cause?"
- "How would you approach this?"
- "What am I missing?"
- "How do I test this?"
5. ITERATE
- Try the solution
- Report what happened
- Get refined answer