1. Frame the problem
Every project starts with a clear question. Translate a business need ("why are customers leaving?") into a measurable target ("predict which customers will cancel in the next 30 days").
Decide up front how success will be measured — accuracy, revenue impact, time saved — so you know when the work is done.
- Who will use the result, and how?
- What decision will change because of it?
- What data exists, and what would you need to collect?
2. Collect and clean the data
Real-world data is messy. Expect missing values, duplicates, inconsistent formats and outliers. Cleaning usually takes more time than modelling — and matters more.
- Missing values: drop, fill with a statistic (median/mode), or model them
- Duplicates: identify by a key and remove
- Types: parse dates, convert numeric strings, standardise categories
- Outliers: investigate before removing — they may be the signal
import pandas as pd
df = pd.read_csv("customers.csv")
df = df.drop_duplicates(subset="customer_id")
df["signup_date"] = pd.to_datetime(df["signup_date"])
df["monthly_spend"] = df["monthly_spend"].fillna(df["monthly_spend"].median())
df.info()3. Explore the data (EDA)
Exploratory data analysis builds intuition. Look at distributions, relationships between variables and differences between groups before you build anything.
- Summary statistics: mean, median, standard deviation, percentiles
- Distributions: histograms and box plots
- Relationships: scatter plots and correlation matrices
- Segments: group-by comparisons (e.g. churn rate by plan type)
4. Statistics you will use constantly
- Mean vs median — the median is robust to outliers
- Variance and standard deviation — how spread out values are
- Correlation — strength of a linear relationship (not causation)
- Sampling and the central limit theorem — why averages of samples behave predictably
- Hypothesis testing and p-values — is a difference likely to be real or chance?
- Confidence intervals — a range of plausible values for an estimate
5. Build a model
Choose the simplest model that answers the question. Start with a baseline (e.g. always predicting the most common class) so you can tell whether a model actually adds value.
- Regression — predicting a number (price, demand)
- Classification — predicting a category (churn / no churn)
- Clustering — finding natural groups without labels
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
X = df[["tenure_months", "monthly_spend", "support_tickets"]]
y = df["churned"]
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
model = LogisticRegression(max_iter=1000).fit(X_train, y_train)6. Evaluate honestly
Always evaluate on data the model has never seen. Pick metrics that match the problem — accuracy can be misleading when one class is rare.
- Regression: MAE, RMSE, R²
- Classification: precision, recall, F1-score, ROC-AUC
- Use cross-validation for a more stable estimate
- Watch for overfitting: great training scores, poor test scores
7. Communicate the result
A model nobody understands rarely gets used. Lead with the answer, show one or two clear charts, explain limitations and recommend a next action.