Machine learning at work: what does it solve?
In regular programming you write the rule: “if an invoice exceeds 10,000, ask the manager to approve”. In machine learning you give the system past examples and it works out the rule itself. That helps when a rule is hard to write by hand, like “which customer is about to stop buying from us?”.
| Problem type | The question | Nakhla example |
|---|---|---|
| Classification | Which category? (yes/no, A/B/C) | Will this store stop ordering? Is this invoice suspicious? |
| Regression | How much? (a number) | How many cartons will we sell next month? |
| Clustering | Who is similar to whom? (no answers given) | Splitting customers into segments by buying behaviour |
Classification and regression are supervised learning: your data includes the right answer for every example (did the customer actually leave? how much did we actually sell?). Clustering is unsupervised: there are no answers, and the model finds the groups itself.
What does “learning” actually mean? Run this code: we have study hours and results for 8 students, and the code tries every possible rule and keeps the one that's right most often. That's learning at its simplest: data + a goal + trial.
# Learn a rule from data hours = [1, 2, 3, 4, 5, 6, 7, 8] passed = [0, 0, 0, 1, 0, 1, 1, 1] best_t, best_ok = 0, 0 for t in range(0, 10): ok = 0 for h, p in zip(hours, passed): guess = 1 if h >= t else 0 if guess == p: ok += 1 if ok > best_ok: best_t, best_ok = t, ok print("Best rule: hours >=", best_t) print("Correct:", best_ok, "of", len(hours))