Real projects are more than choosing an algorithm. They follow a workflow, and the same workflow appears in many applications.
The Machine Learning Workflow
- Define the problem and the success measure, such as detecting customers likely to leave.
- Collect and understand the data, checking quality and missing values.
- Prepare the data: clean it, encode categories, scale numbers, and split into training, validation and test sets.
- Choose and train models, beginning with a simple baseline.
- Evaluate with the right measure, using cross-validation, then on the test set once.
- Deploy the model and monitor its performance as the data changes.
Case Study: Predicting Customer Churn
A telecom company wants to find customers who are about to cancel, so that it can offer them a better plan. The data holds usage, billing, complaints and contract length, and the label is whether the customer left. The problem is binary classification with imbalanced classes, since only a quarter of customers leave. Accuracy is therefore a poor measure; the company cares about recall (how many leavers are found) and precision (how many offers are not wasted). A logistic regression or a decision tree is built first; the final model is chosen with cross-validation.
Other Applications
Healthcare: detecting disease in scans. Finance: fraud detection and credit scoring. Retail: recommendation and demand forecasting. Agriculture: crop disease and yield prediction. Transport: traffic prediction and route planning. Education: identifying students at risk of dropping out. Each needs the ethical care discussed in the previous topic.
Definition: Machine learning workflow. The sequence of steps in a project: define the problem, collect data, prepare it, train models, evaluate them, and deploy and monitor the chosen model.
Table 4.7: Applications and the ML task
| Domain | Application | Task | Typical measure |
|---|---|---|---|
| Telecom | Customer churn | Classification | Recall, F1 |
| Banking | Fraud detection | Classification | Precision, recall |
| Retail | Sales forecast | Regression | MSE |
| Marketing | Customer segments | Clustering | Silhouette |
| Healthcare | Disease from scans | Classification | Recall, AUC |
Example 4.7: Evaluating the churn model
Problem: On 200 test customers the churn model gives TP = 30, FP = 10, FN = 20 and TN = 140. Find accuracy, precision, recall and F1, and say whether accuracy alone is a good measure.
Solution:
- Accuracy = (30 + 140) / 200 = 0.85.
- Precision = 30 / (30 + 10) = 0.75.
- Recall = 30 / (30 + 20) = 0.60.
- F1 = 2 × 0.75 × 0.60 / (0.75 + 0.60) = 0.90 / 1.35 = 0.667.
- A model that predicted "stays" for everyone would score (140 + 10) / 200 = 0.75 accuracy, so 0.85 is less impressive than it looks. Recall of 0.60 shows that 40 percent of leavers are missed.
Result: Accuracy 0.85, precision 0.75, recall 0.60, F1 0.667; accuracy alone is misleading here.
tp, fp, fn, tn = 30, 10, 20, 140
n = tp + fp + fn + tn
acc = (tp + tn) / n
p = tp / (tp + fp)
r = tp / (tp + fn)
print("accuracy", acc, "precision", p, "recall", r)
print("F1", round(2 * p * r / (p + r), 3))
print("accuracy of always predicting stay:", (tn + fp) / n)
Output
accuracy 0.85 precision 0.75 recall 0.6
F1 0.667
accuracy of always predicting stay: 0.75
Common mistakes
- Starting with a complicated model before building a simple baseline.
- Using accuracy on imbalanced data such as churn or fraud.
- Treating deployment as the end; models drift and need monitoring.
- Ignoring ethical review for applications that affect people.
Key takeaways
- Workflow: problem, data, preparation, model, evaluation, deployment, monitoring.
- Always begin with a simple baseline.
- Choose the measure to match the business cost.
- Domains such as health, finance and retail use classification, regression and clustering.
Practice questions
- List the first three steps of an ML project.
- Why is accuracy a poor measure for churn?
- What should happen after deployment?
Answers to the practice questions
- Define the problem, collect the data and prepare the data.
- The classes are imbalanced, so a model that predicts everyone stays still scores high.
- Monitor the model and retrain when the data changes.
Sources
- Official BCA syllabus Introduction to Machine Learning, course code 26BCA404DSE21, Unit IV
