Robot Learning · Theory · M2
M2-T1 — Regression and Classification for Robots
Most robot prediction problems are one of two kinds: predict a number, or predict a label. Each has its own error measure, and each needs a baseline to beat.
A robot log is a table: each row is a moment, each column something the robot sensed or did. Supervised learning picks one column to predict from the others. If that column is a number (a steering command, a distance to the wall, a battery level) the problem is regression. If it is a label (corridor blocked or clear, door A, B or C) it is classification. The choice sets the output of the model, the loss it trains on and the metric that tells you whether it works. This lesson also builds the habit that carries through the module: compute the dumbest possible baseline first, because a score means nothing until you know what a model that learned nothing would score.
Learning objectives
After this lesson, you should be able to:
- Classify a robot prediction problem as regression or classification and name its inputs and outputs.
- Compute MSE, RMSE and MAE for a regression, and accuracy, precision, recall and a confusion matrix for a classifier.
- Compare a model with the mean baseline and the majority-class baseline, and say what the comparison shows.
- Explain why fitting a policy to logged actions is supervised learning, and what that leaves unsolved before module M3.
The intuition
Imagine a table of Scout’s past drives. One column says how far off the corridor centre Scout was; another says what steering command the operator gave. A new drive arrives with only the first column. Regression is the job of guessing the second column. The shape of the answer matters: steering is a number on a scale, and guessing 0.30 when the truth is 0.35 is nearly right while guessing −0.30 is badly wrong. The error has a size.
Now ask a different question of the same logs: is the corridor ahead blocked? The answer is yes or no. Guessing “blocked” when it is clear is wrong, full stop; there is no “nearly right”. That is classification, and its errors are counted, not measured. Counting leads to the confusion matrix, which also separates two kinds of mistake with different costs: stopping for nothing, and driving into a cart.
The figure shows the regression case with six logged pairs. The orange dashed line is the best guess that ignores the input (the mean steering). The blue line is a fit that uses the offset. The green bars are the residuals, the gaps the metrics summarise.
The mathematics
The setup
A supervised dataset is a set of pairs (xi, yi), i = 1…n. The model f maps an input to a prediction ŷ = f(x). In the Scout world of this track, x is an observation such as [dx, dy, px, py] and y is the logged action.
- x
- input features: what the robot knew at that moment (a vector)
- y
- target: a real number or vector (regression) or one of K labels (classification)
- ŷ = f(x)
- the model’s prediction
- ri = ŷi − yi
- residual: prediction minus truth
- n
- number of examples scored
Regression metrics
RMSE squares before averaging, so one large miss counts more than several small ones. MAE weights all misses in proportion to their size. Reporting both is cheap and tells you whether errors are many and small or few and large. For steering in [−1, 1], an RMSE of 0.05 means a typical error of about 5% of full lock.
Classification metrics
For two classes, call the class you care about “positive” (corridor blocked). Every prediction falls in one cell of the confusion matrix.
| Predicted blocked | Predicted clear | |
|---|---|---|
| Truly blocked | TP (true positive) | FN (false negative: missed obstacle) |
| Truly clear | FP (false positive: needless stop) | TN (true negative) |
Accuracy hides the trade-off. A detector that always says “clear” can be 90% accurate when 90% of corridors are clear, and it never stops for an obstacle. Precision is what you pay for false alarms; recall is what you pay for misses. Which matters more is a decision about the robot, not about the model: a hospital delivery robot usually values recall of blocked corridors above precision. Most classifiers output a score and a threshold turns it into a label; moving the threshold trades one for the other.
With K classes (which door?) the confusion matrix is K × K, the diagonal holds the correct cases, and precision and recall are computed per class.
Baselines
- Regression baseline: predict the training mean for every input. Its MSE is the variance of y, and R² = 0 by definition.
- Classification baseline: predict the most frequent class. Its accuracy is that class’s share; its recall for the other class is zero.
- Domain baseline: a hand-written rule, such as “steer opposite to the offset”. If a learned model cannot beat a one-line rule, it has not learned much.
Why this is the first step toward imitation
A demonstration is a log of (observation, action) pairs. Fitting a model from observation to action is regression when actions are continuous (the velocity command of module M1) and classification when they are discrete (left, straight, right). Behaviour cloning, module M3, is exactly this fit followed by running the model as a policy. The catch, which lesson M1-T6 previewed, is that a good score on the logged pairs does not bound how the policy behaves once its own errors change what it sees next.
A worked example
All values below were computed by running code (JavaScript, with the mean and fit checked by hand against the normal equations).
Regression: steering from lateral offset
Six logged pairs (offset in m, steering in [−1, 1]): (−0.6, 0.45), (−0.3, 0.35), (0.0, 0.05), (0.2, −0.15), (0.5, −0.30), (0.8, −0.65). The mean offset is 0.100 and the mean steering is −0.0417.
Baseline. Predict −0.0417 for every row. MSE = 0.1420, RMSE = 0.3768, MAE = 0.3250.
Fitted line. The least-squares slope is Sxy / Sxx = −1.05 / 1.32 = −0.7955 and the intercept is −0.0417 − (−0.7955)(0.100) = 0.0379, so ŷ = 0.0379 − 0.7955·x. The predictions are 0.5152, 0.2765, 0.0379, −0.1212, −0.3598, −0.5985, and the residuals are +0.0652, −0.0735, −0.0121, +0.0288, −0.0598, +0.0515.
| Model | MSE | RMSE | MAE | R² |
|---|---|---|---|---|
| Mean baseline | 0.1420 | 0.3768 | 0.3250 | 0.000 |
| Line ŷ = 0.0379 − 0.7955 x | 0.0028 | 0.0530 | 0.0485 | 0.980 |
The line cuts RMSE from 0.377 to 0.053, a factor of 7. For a new offset of 0.4 m it predicts 0.0379 − 0.7955 × 0.4 = −0.280: steer left by 28% of full lock.
What this does not show. These scores are on the six rows used to fit the line, so they are optimistic: a line has two parameters and six points. Module M2 spends lessons M2-T5 and M2-T6 on honest held-out scores.
Classification: is the corridor blocked?
Twelve forward range scans, 4 truly blocked and 8 clear. A classifier says “blocked” for 5 of them: 3 correct and 2 false alarms, and it misses 1 blocked scan.
| Predicted blocked | Predicted clear | Row total | |
|---|---|---|---|
| Truly blocked | TP = 3 | FN = 1 | 4 |
| Truly clear | FP = 2 | TN = 6 | 8 |
Accuracy = (3 + 6) / 12 = 0.750. Precision = 3 / 5 = 0.600. Recall = 3 / 4 = 0.750. F1 = 2·3 / (2·3 + 2 + 1) = 0.667. The majority-class baseline always says “clear”: accuracy 8 / 12 = 0.667, recall 0. The classifier beats it by only 8 points of accuracy, but it catches 3 of the 4 blocked corridors, which the baseline never does. Accuracy alone would have called the two nearly equal; recall shows they are not.
Uncertainty. With 12 scans, one different prediction moves accuracy by 8 points. A real evaluation needs hundreds of scans and an interval (lesson M1-T5 gave the tools); the point here is the arithmetic.
The same split on Scout’s world
The expert’s action in RLCore is a pair of numbers in [−1, 1], so cloning it is regression. In lesson M1-T6, the fitted linear policy’s training MSE was 0.0745 with raw [dx, dy, 1] and 0.0593 with unit-direction features, yet success was 0 of 100 and 45 of 100. A lower regression error did not mean a policy that works. Lab M2-L1 asks you to fit exactly this regression with gradient descent.
Engineering implications and limitations
Pick the output type from the decision
If downstream code needs a number (a velocity), regress. If it chooses between actions (stop or go), classify. A common error is to regress a label such as door number 1, 2, 3, which imposes an order and distances (door 3 is “twice” door 1) that do not exist. Use one output per class instead.
Report the baseline next to every score
“RMSE 0.05” is meaningless alone. “RMSE 0.05 against 0.38 for the mean” is a result. Log the baseline in the same table, from the same split.
Check class balance and error costs
Blocked corridors may be 2% of the log. Then “always clear” scores 98% accuracy. Count the classes, report recall and precision for the rare one, and choose the threshold with the cost of each mistake in view.
Match the metric to the use
RMSE punishes rare large errors, which is right for a collision-avoidance command and perhaps wrong for a noisy sensor with occasional garbage readings. MAE is more tolerant. Look at the residuals as a list, not just their average.
Units and clipping
Report error in physical units where you can (metres, degrees, m/s), and say whether the target is clipped. A steering command saturated at ±1 hides how hard the operator pushed.
What the simulation simplifies
Scout’s world has no sensing noise and the expert is a deterministic function of the observation, so the regression target is a clean function and the achievable error is not limited by label noise. Real logs have noisy operators, delays between sensing and acting, and mislabeled frames; the achievable error is above zero and often unknown.
Common misconceptions
“Higher accuracy means a better classifier.”
Only against the right baseline and when classes are balanced. With 8 clear scans in 12, “always clear” scores 0.667 and catches no obstacles.
“A regression is good if the error is small.”
Small compared with what? Compare with the mean baseline (here RMSE 0.377) and with the size of the target; RMSE 0.05 is excellent on a range of ±1 and poor on a range of ±0.05.
“Cloning a policy is a different kind of learning.”
The fit is ordinary supervised regression. What makes imitation harder is deployment: the policy’s own mistakes change its future inputs, so the training score does not predict the success rate.
“Precision and recall measure the same thing.”
Precision counts false alarms, recall counts misses. Raising the threshold usually raises precision and lowers recall.
Engineering takeaways
- Predicting a number is regression (MSE, RMSE, MAE); predicting a label is classification (confusion matrix, precision, recall).
- Always compute the baseline first: the mean for regression, the majority class for classification.
- On six steering pairs a fitted line has RMSE 0.053 against 0.377 for the mean; on 12 scans a classifier has accuracy 0.75 against 0.667 for “always clear”, but recall 0.75 against 0.
- Accuracy hides the cost of misses; choose precision, recall and the threshold from the cost of each mistake.
- Behaviour cloning is regression on logged actions; the score on the log does not guarantee the closed-loop success rate (module M3).
References and further reading
Standard textbooks for the metrics and for the supervised-learning setup.
- T. Hastie, R. Tibshirani and J. Friedman, “The Elements of Statistical Learning”, 2nd ed., Springer, 2009.
- C. M. Bishop, “Pattern Recognition and Machine Learning”, Springer, 2006.
- I. Goodfellow, Y. Bengio and A. Courville, “Deep Learning”, MIT Press, 2016.
Knowledge check
Three conceptual questions. Write an answer, then reveal the explanation. Your answers stay in your browser.
Question 1
Classify as regression or classification: (a) the steering angle to command, (b) whether the door ahead is open, (c) the distance to the nearest wall in metres, (d) which of three docking stations to approach.
Explanation
(a) regression, (b) classification (two classes), (c) regression, (d) classification (three classes).
Question 2
A classifier flags 10 scans as blocked; 7 are truly blocked. There are 14 truly blocked scans in all. Give precision and recall.
Explanation
Precision = 7 / 10 = 0.70 (7 true positives out of 10 flagged). Recall = 7 / 14 = 0.50 (7 of the 14 blocked scans were caught).
Question 3
A steering model has RMSE 0.20 on a log whose steering has standard deviation 0.20. Is it useful?
Explanation
No. The mean baseline has RMSE equal to the standard deviation of y (0.20), so the model does no better than ignoring the input; R² is about 0.
What’s next
Next: lesson M2-T2 asks what to feed the model. The same linear fit scored 0 of 100 on raw [dx, dy] and 88 of 100 on easy starts with unit-direction features, and the difference lies in the inputs.
Related content
Nothing below is required to finish this lesson.
- LabM2-L1: Fit Steering with Gradient Descent
Predict Scout's steering command from its state with a linear model trained by gradient descent that currently diverges.
Get notified when the next lesson and new labs are released.
One email per new lesson or lab.