MyMisPal
← Practical AI lessons
Lesson 1 of 11

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?”.

Nakhla scenarioNakhla Distribution (from the ERP and BI tracks) has years of data: sales, customers, invoices. Management asks: “Can this data help us predict what's coming?”. In this track you'll build simple models in Python from scratch and run them right here in your browser.
Problem typeThe questionNakhla example
ClassificationWhich category? (yes/no, A/B/C)Will this store stop ordering? Is this invoice suspicious?
RegressionHow much? (a number)How many cartons will we sell next month?
ClusteringWho 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.

PYTHON
# 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))
Watch outNot every problem needs ML. If the rule is clear and stable, like calculating 15% VAT, just write it: faster, cheaper and the same result every time. ML is worth it when the rule is fuzzy and you have enough past data.

Exercises

Exercise 1 · Classifying

Sort each question by problem type:

Is this email a scam?
What will next Ramadan's sales be?
Group similar customers without any labels
Will the store stop ordering within 3 months?
How many days late will this supplier deliver?
Exercise 2 · Multiple choice

Which task does not need machine learning?

Exercise 3 · Multiple choice

In the study-hours code, why did the best rule get 7 of 8 rather than all 8?

Spotted a mistake on this page, or have an idea to improve the site?