Home›Part 2 Machine Learning Basics›2.1

Part 2 · Machine Learning Basics

2.1 What is machine learning?

Teaching with data instead of writing rules

8-minute readPrerequisite: none▶ Video (about 5 min)

What you will learn

  • Explain the difference between conventional programs, where people write the rules, and machine learning, where rules are learned from data
  • Explain, with examples, the difference between supervised learning (regression and classification), unsupervised learning and reinforcement learning
  • Explain what model, parameter, training, inference and generalization mean, and why the performance of machine learning is determined by data

Build intuition

Imagine writing a program that finds pedestrians in camera images using hand-written rules: “a tall, narrow shape, 1–2 m high, with arms and legs…”. But then there are people holding umbrellas, people pushing bicycles, crouching children, people carrying large bags, people in the dark at night — the exceptions never end. The more conditions you add, the more complicated the rules become, and some cases still slip through.

Machine learning turns this around. Instead of people writing the rules for the decision, we prepare large amounts of labeled data — “this is a pedestrian”, “this is not a pedestrian” — and let the computer build the decision procedure itself from the data. The resulting decision procedure is called a model.

Conventional program People write the rules Input Rules written by people Output Machine learning The rules are learned from data Labeled data Training Model (learned rules) Prediction New input Inference
In a conventional program, people write the rules for the decision. In machine learning, a model (the rules) is built from labeled data (training), and that model is then used to make predictions for new inputs (inference).

Building the model is called training; using the finished model to answer new inputs is called inference. Training happens during development, using large amounts of data and time; inference happens inside the vehicle, in a split second.

Depending on what is learned and how, machine learning falls into these broad types:

TypeWhat it learnsExample in automated driving
Supervised learning (regression)Predicts a number from the inputWhere the vehicle ahead will be in 3 seconds
Supervised learning (classification)Predicts a category from the inputWhether an object in the camera image is a pedestrian, a cyclist or a car
Unsupervised learningFinds groupings or “unusual items” in data without answersGrouping similar situations in large driving logs, or finding rare ones
Reinforcement learningLearns, by trial and error, actions that earn a larger rewardLearning how to drive inside a simulation

This course focuses on supervised learning, the most widely used type.

Check with math

① A model is a function with adjustable knobs

$$\hat{y} = f(x;\ \theta)$$

x is the input (an image, a sensor measurement and so on) and \(\hat{y}\) is the prediction (the hat marks an estimated value, as in 1.6). θ (theta) stands for the model’s parameters — the “knobs” that determine how the model behaves. The simplest example is a straight line, \(\hat{y} = ax + b\), with just two knobs, a and b. Deep learning models that handle images can have millions to billions of knobs.

② Training means finding the knob settings with the smallest gap

For labeled data \((x_1, y_1), \dots, (x_n, y_n)\), we measure the gap between each prediction and the correct answer with L, and choose the parameters that make the average gap smallest.

$$\theta^{*} = \arg\min_{\theta}\ \frac{1}{n}\sum_{i=1}^{n} L\big(y_i,\ f(x_i;\theta)\big)$$

\(\arg\min_{\theta}\) (“arg min”) means “the θ that makes the expression on the right smallest” (see Notation). The way of measuring the gap, L, is called the loss function; it is covered in 2.2 Linear regression and loss functions. How to find the θ that minimizes it is the subject of 2.3 Gradient descent.

③ What matters is performance on data the model has not seen

Fitting the training data perfectly means little on its own. What we really want to know is how well the model does on new data that was not used for training — its generalization performance. That is why part of the available data is held back from training and used for testing. It is the same idea as in 1.6, where we inferred the true detection rate from test results. This is covered in more depth in 2.6 Overfitting and regularization and 2.8 Data splits and distribution shift.

Connection to automated driving

  • Used where rules cannot cover everything: machine learning is used where the conditions are endless — recognizing objects with cameras and LiDAR, predicting how surrounding vehicles and pedestrians will move, and so on. → 4.2 System overview
  • The specification moves into the data: with conventional software, you could check the behavior by reading the specification and the code. With machine learning, the data it was trained on determines its behavior. Biases and gaps in the data become gaps in performance — what SOTIF calls functional insufficiencies. → 5.3 Functional insufficiencies and triggering conditions
  • There is no 100%: however much it is trained, a model will sometimes be wrong. Its performance is estimated from tests, as in 1.6, and reported with an interval. → 2.7 Evaluation metrics
  • Weak in situations it has never seen: outside the range of the training data — outside the ODD, with new kinds of objects, in unfamiliar weather — predictions cannot be trusted. → 2.8 Data splits and distribution shift, 5.9 Safety of AI components

Summary

  • Machine learning builds rules (a model) from labeled data instead of having people write the rules
  • Supervised learning includes regression, which predicts numbers, and classification, which predicts categories. There are also unsupervised and reinforcement learning
  • Training means finding the parameters that make the gap between predictions and answers (the loss) smallest. What matters is performance on data not used for training (generalization performance)

Quick quiz

Q1. Which is better suited to machine learning? (a) Issuing a warning when the speed limit is exceeded (b) Finding pedestrians in camera images

(b). (a) can be written as a clear rule — “speed > speed limit” — so there is no need for machine learning. (b) has countless exceptions in how pedestrians look and cannot be fully written as rules, so learning from data is a good fit.

Q2. Are “predicting where the vehicle ahead will be in 3 seconds” and “recognizing the color of a traffic light” regression or classification?

Predicting a position gives a number, so it is regression; the color of a light (red, yellow, green) is a category, so it is classification.

Q3. Tested on its own training data, a model scored 99% accuracy. Can you say it will reach 99% in real use?

No. A model can score highly on its training data simply by memorizing it (overfitting, covered in 2.6). Performance must be measured on data not used for training — and you also need to check that real-world data does not differ from the test data.

Q4. All the images used to train a pedestrian detector were taken in daytime. What is likely to happen to pedestrian detection at night?

Performance is likely to drop, because the model cannot handle situations missing from its training data well. Conditions absent from the training data, such as night-time, are candidate triggering conditions in SOTIF terms.

Further reading