AI Compass
Compass

What machine learning is

The difference between programmed rules and learned rules, the three kinds of learning, and the question of when machine learning is worth it at all.

·2 min read·By Fachredaktion Technik
DETAIL
3 sections

What this is about

To teach a program to tell an invoice from a delivery note there are two routes. The classical one: somebody writes rules. "If the phrase invoice number appears, then …". The second: show the program ten thousand invoices and ten thousand delivery notes and let it work out for itself where the difference sits.

The second route is machine learning. It pays off whenever the rules have too many exceptions to write down.

The three kinds

KindWhat you haveExample
SupervisedExamples with the right answerInvoice or delivery note, labelled
UnsupervisedExamples without answersFinding customer groups without knowing which
ReinforcementReward for good decisionsRobot arm, game strategy, control systems

The sequence that never changes

  1. 01

    Define the question

    What exactly is to be predicted, and how will you know the answer was right? Settling this before the data saves the most time.

  2. 02

    Split the data

    Training, validation, test. The test set is touched exactly once, at the very end. See Cross-validation.

  3. 03

    Establish a baseline

    How good is the simplest conceivable rule? Without that reference no progress can later be claimed.

  4. 04

    Fit and evaluate

    Only now come model choice and hyperparameters, in that order and not the other way round.

When ordinary programming is better

  • The rule is known and stable, such as a statutory deadline.
  • There are fewer than a few hundred examples.
  • Every individual case must be justifiable and an approximation will not do.
  • The failure case is expensive and rare. Then you check everything instead.

What a model formally does

The learning problem

f* = argmin_f R(f), R(f) = E₍ₓ,ᵧ₎∼𝓓 [ L(f(x), y) ]

You are looking for the function with the smallest average error on data you have never seen.

𝓓
the unknown distribution the data comes from
f
the function sought, from a hypothesis class
L
the loss function
R
expected risk: the average error on unseen data

The problem: 𝓓 is unknown. You minimise empirical risk on the sample instead, and the rest of the discipline is about the gap between the two, see Overfitting, bias and variance.

A complete example

from sklearn.datasets import load_breast_cancer
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import classification_report

X, y = load_breast_cancer(return_X_y=True)
Xtr, Xte, ytr, yte = train_test_split(X, y, test_size=0.25,
                                      stratify=y, random_state=0)

# stratify=y keeps the class balance identical in both parts; without it
# the measured quality moves purely because of the split.
model = LogisticRegression(max_iter=5000).fit(Xtr, ytr)
print(classification_report(yte, model.predict(Xte), digits=3))

The mistake that costs most

Building a model before the success measure is fixed. With no metric and no baseline agreed in advance, what gets searched for at the end is the metric on which the model looks good. That is no longer an evaluation but a narrative.

Related courses and sources

ToolFreeEN

Jupyter

Notebooks where text, code and result sit side by side. The usual tool for recording a calculation so that others can follow it.

For your first calculations; keeps text, code and result traceable in one place.

CourseFree600 minEN

Kaggle Learn

Short units with runnable notebooks, from Python through pandas to a first model. No installation, straight in the browser.

For the very first steps with no installation, straight in the browser.

CoursePartly free5400 minEN

Machine Learning Specialization

Andrew Ng's course in its reworked form. Regression, classification, neural networks and the mistakes that actually happen in practice. The maths is included.

Free to audit; the certificate costs. If you only want to understand it, you do not need one.

DeepLearning.AIGo to offer
CourseFree3000 minEN

MIT 6.036 Introduction to Machine Learning

More formal than most online courses, with derivations rather than recipes. A good follow-up to a hands-on course when the question of why is still open.

For anyone left with the question of why after a hands-on course.

MIT OpenCourseWareGo to offer
BookFreeEN

Probabilistic Machine Learning

Kevin Murphy's volumes, building machine learning consistently out of probability theory. Extensive and freely available.

For anyone wanting machine learning built consistently out of probability theory.

ArticleFreeEN

scikit-learn user guide

Not a manual but a textbook with code. Every method comes with a note on when it does not fit, which textbooks rarely state so plainly.

For anyone using classical methods; each one comes with a note on when it does not fit.

scikit-learnGo to offer
Was this page helpful?
What machine learning is