Lesson 4 of 13 · What Is ML?
Where ML Is Used
How machine learning is used in healthcare, finance, shopping, transport and farming, a tiny recommender in Python, and four signs a problem suits ML.
- 5 min read
- Beginner
- Reviewed
- Give real examples of machine learning across different industries
- Build a tiny recommendation system from purchase history
- Use four questions to judge whether a problem suits machine learning
- Recognise problems where machine learning is the wrong tool
Machine learning all around you
| Area | Example | Type |
|---|---|---|
| Healthcare | Spotting signs of disease in scans, to help doctors prioritise | Classification |
| Finance | Flagging card payments that look like fraud | Classification |
| Shopping | “Customers who bought this also bought…” | Recommendation |
| Transport | Predicting journey times from live traffic | Regression |
| Energy | Forecasting electricity demand for tomorrow | Regression |
| Farming | Detecting crop disease from drone photos | Classification |
| Customer service | Routing emails to the right team | Classification |
| Language | Translation, speech recognition, chat assistants | Deep learning |
Build a tiny recommender
Recommendation systems learn from what people did. The simplest version counts which items appear together in the same basket:
# "Customers who bought this also bought...": learning from purchase history
baskets = [
{"tent", "sleeping bag", "torch"},
{"tent", "sleeping bag"},
{"torch", "batteries"},
{"tent", "torch", "batteries"},
{"sleeping bag", "pillow"},
{"tent", "sleeping bag", "pillow"},
]
def also_bought(item):
counts = {}
for basket in baskets:
if item in basket:
for other in basket - {item}:
counts[other] = counts.get(other, 0) + 1
return sorted(counts.items(), key=lambda pair: (-pair[1], pair[0]))
for item in ["tent", "torch"]:
bought_with = also_bought(item)
print(f"People who bought a {item} also bought:", ", ".join(f"{name} ({n})" for name, n in bought_with))Nobody wrote a rule saying “tents go with sleeping bags”. The pattern came from the data, and it would update by itself as more people shop. Real recommenders use millions of baskets and smarter methods, but the core idea is the same.
Is it a good machine learning problem?
Ask four questions:
- Is there a pattern? Past data must say something about the future. Lottery numbers have no pattern; house prices do.
- Is there enough data? For supervised learning, you need many examples with the right answers.
- Are mistakes acceptable? Every model is sometimes wrong. A wrong film suggestion costs nothing; a wrong medical decision needs a doctor to check.
- Is it hard to write the rules by hand? If you can write a clear rule (“orders over 50 euros ship free”), write it. Machine learning is for patterns too complex or changing too fast to write down.
Common mistakes
Recommendation systems start by counting which items are bought together. Count one pair.
baskets = [
{"tent", "sleeping bag", "torch"},
{"tent", "sleeping bag"},
{"torch", "batteries"},
{"tent", "torch", "batteries"},
]
# How many baskets contain BOTH "torch" and "batteries"? Print just the number.
Which problem is the WORST fit for machine learning?
Summary
- Machine learning is used in healthcare, finance, shopping, transport, energy, farming and more.
- A simple recommender can learn from which items are bought together.
- Good ML problems have a pattern, enough data, acceptable mistakes, and rules that are hard to write by hand.
- Start from the goal, not the technology, and take extra care where decisions affect people.
Next: features and labels, the building blocks of every dataset.
Finished reading? Tick it off to track your progress.