III-03 · Learning Problems

Choose the task from what the answer means

The same numeric target codes can describe categories or measurements. Inspect the goal before naming the algorithm.

Chapters in Part I
  1. III-01 · What Machine Learning Actually Learns
  2. III-02 · Samples, Features, Labels and Targets
  3. III-03 · Learning Problems
  4. III-04 · Training, Validation, Testing and Generalization
  5. III-05 · Parameters, Hyperparameters, Loss and Optimization
  6. III-06 · Underfitting, Overfitting, Bias, Variance and Baselines

Decide what the target means

Six explicit hand-authored scenarios. This decision sheet fits no regressor, classifier or clustering model.

Predict sale price in euros from area and age.

Reconsider this goal. The target is a numerical amount or measured proportion.

Goal
Supervised
X
3 × 2
Targets used by this goalThe target is a numerical amount or measured proportion.
3 × 1
Inspect features, recorded targets and whether the goal uses them.
RowFeature 1Feature 2Recorded targetUsed by goal?
14010100000Yes
2705180000Yes
31001260000Yes

Identical numeric codes can denote categories or measurements. Choose from the goal and semantics; storage dtype alone cannot decide.

Frame 1 / 1 · edits start from the displayed state.

Select one of six goals, inspect its observed features and targets, and choose the learning task. Feedback follows the goal and target semantics rather than the storage dtype.

What would count as a correct answer?

A predicted sale price is an amount. A predicted spam label is a category. A grouping of customers is a discovered structure. All three can use numerical features, but they ask for different kinds of outputs and require different evaluation criteria.

A supervised problem uses observed targets to judge predictions. Regression predicts a numerical quantity, such as price or a measured proportion. Classification predicts a category, such as spam or ordinary mail. Unsupervised exploration searches for structure using inputs without a target used by that goal. It still needs an objective: grouping nearby feature vectors is one possible goal, not the definition of every unsupervised method.

These names describe a problem and information flow. They do not prescribe a particular algorithm, guarantee quality, or establish that an input causes an output.

State the problem before choosing a method

For supervised learning, the observed dataset can be written

D={(xi,yi)}i=1n,y^i=fθ(xi).D=\{(\mathbf{x}_i,y_i)\}_{i=1}^{n}, \qquad \hat y_i=f_\theta(\mathbf{x}_i).

A regression target belongs to a numerical measurement space with meaningful differences. For classification, yi∈Cy_i\in\mathcal C, where C\mathcal C is a set of category identifiers. A classification model may compute numeric scores or probabilities internally, but its category labels are not measured quantities merely because they have numeric codes.

For an unsupervised grouping goal, write DX={xi}i=1nD_X=\{\mathbf{x}_i\}_{i=1}^n. A method might return group assignments gig_i and representative group centers. There is no supplied supervised yiy_i against which a signed regression residual is automatically meaningful.

The sheet’s decision rule is explicit:

  1. Does this goal use an observed target? If no, the demonstrated goal is unsupervised.
  2. If yes, does that target denote a category? Then the task is classification.
  3. If it denotes a measured amount, the task is regression.

This is a rule for the six declared examples. Structured outputs, self-supervised objectives and reinforcement learning need richer descriptions than these introductory branches.

Work the numeric-code counterexample

Two scenarios deliberately use the same feature matrix

X=[123021]∈R3×2.X=\begin{bmatrix}1&2\\3&0\\2&1\end{bmatrix}\in\mathbb R^{3\times2}.

In one scenario, targets [0,1,0]T[0,1,0]^{\mathsf T} are two category identifiers. The goal is classification. Replacing code 00 with the name ordinary and code 11 with spam changes the encoding, not the task.

In another, targets [0,0.4,1]T[0,0.4,1]^{\mathsf T} measure a fraction of time in sunlight. Differences have quantitative meaning and intermediate values are valid: the goal is regression.

For a regression prediction 0.60.6 against measurement 0.40.4, the residual is 0.20.2 and squared error is 0.040.04. For a category coded 11 against category coded 00, the numeric difference is not inherently a physical prediction error. A third category could be coded 100100 without becoming one hundred times farther from the first. Choosing a suitable classification loss belongs to later chapters.

Labels can exist without being used by the goal

The “explore features without using labels” scenario records labels a, a and b, but its specified goal groups rows using only features. This goal is unsupervised. The labels are displayed as recorded metadata, while the inspector correctly marks a target used by this goal as absent.

One file can support several different learning questions. Predicting its labels would use supervision; exploring feature clusters while ignoring those labels would not. Inspecting labels repeatedly to tune the grouping would change that information boundary and should be disclosed as part of the procedure.

Execute the actual decision reference

The imported Python creates NumPy feature arrays and an observed target column only when the stated goal uses it. The decision branches depend on declared semantic type, not a dtype heuristic. Run .venv/bin/python -B code/python/p01/learning_problems.py to see all six correct decisions and their shapes.

code/python/p01/learning_problems.py
"""III-03: target semantics and the intended goal decide the learning task."""
import json
import numpy as np

TASKS = [
    dict(id='price', name='Predict a price', goal='Predict sale price in euros from area and age.', features=[[40,10],[70,5],[100,1]], targets=[100000,180000,260000], kind='quantity', expected='regression'),
    dict(id='spam', name='Predict an email category', goal='Predict spam or ordinary mail from two counts.', features=[[0,2],[6,0],[1,4]], targets=['ordinary','spam','ordinary'], kind='category', expected='classification'),
    dict(id='binary-code', name='Predict a category coded 0/1', goal='Predict an observed category; 0 and 1 are identifiers, not amounts.', features=[[1,2],[3,0],[2,1]], targets=[0,1,0], kind='category', expected='classification'),
    dict(id='proportion', name='Predict a measured proportion', goal='Predict a measured fraction of time in sunlight, including intermediate values.', features=[[1,2],[3,0],[2,1]], targets=[0,.4,1], kind='quantity', expected='regression'),
    dict(id='customers', name='Group customers', goal='Find groups using spending and visit counts; no target is supplied.', features=[[2,1],[3,2],[12,9]], targets=None, kind='none', expected='unsupervised'),
    dict(id='ignore-label', name='Explore features without using labels', goal='Group observations by features; recorded labels are deliberately excluded from this goal.', features=[[1,1],[2,2],[9,8]], targets=['a','a','b'], kind='ignored', expected='unsupervised'),
]
TASK_CANONICAL = dict(scenario='price', choice='unsupervised')

def derive_task(state):
    scenario = next((row for row in TASKS if row['id'] == state['scenario']), None)
    if scenario is None or state['choice'] not in ('regression', 'classification', 'unsupervised'):
        raise ValueError('Choose a known scenario and learning task')
    uses = scenario['kind'] in ('quantity', 'category')
    expected = 'regression' if scenario['kind'] == 'quantity' else 'classification' if scenario['kind'] == 'category' else 'unsupervised'
    X = np.asarray(scenario['features'], dtype=np.float64)
    y = np.asarray(scenario['targets'], dtype=object).reshape(-1, 1) if uses else None
    reason = 'Labels exist, but this grouping goal does not use them.' if scenario['kind'] == 'ignored' else 'No target is observed; this goal explores feature structure.' if not uses else 'The target denotes a category, including when its code is numeric.' if scenario['kind'] == 'category' else 'The target is a numerical amount or measured proportion.'
    return dict(state=state.copy(), scenario=scenario, usesTarget=uses, correct=state['choice'] == expected, supervision='Supervised' if uses else 'Unsupervised', shapes=dict(X=list(X.shape), targets=None if y is None else list(y.shape)), reason=reason)

if __name__ == '__main__':
    print(json.dumps([derive_task(dict(scenario=row['id'], choice=row['expected'])) for row in TASKS], indent=2, allow_nan=False))

An independent literal truth table checks sale price and sunlight proportion as regression; named and numeric-coded categories as classification; and both unlabelled and deliberately label-ignoring grouping goals as unsupervised. These discrete checks use exact comparisons rather than a floating-point tolerance.

Explore the consequences of the goal

Select the coded-category scenario and choose regression. Read the corrective reason, then choose classification. Switch to the measured proportion while keeping the same feature shape: which interpretation must change?

Compare the customer-grouping scenario with the label-ignoring scenario. Both have XX of shape 3×23\times2 and no supervised target used by the goal. One has no recorded labels; the other deliberately excludes them. The distinction matters for provenance even when the selected task name is the same.

Reset returns the price problem and an initial incorrect choice to invite a fresh decision. No classifier or clustering engine runs in this interaction; it is a problem-specification experiment with observable inputs and graded semantic feedback.

Limits and common mistakes

A numeric dtype cannot decide between regression and classification. A binary target is not always a category; a real-valued array is not always a measurement. Conversely, categorical inputs do not make an output task classification. Input representation and target semantics are separate decisions.

The six datasets are explicit hand-authored counterexamples. Their tiny size supplies no evidence of generalization, group quality or fairness. Units are stated in the scenario’s goal; the feature table is an illustrative representation, not a complete production schema.

Problem choice also determines evaluation. Regression may use squared error; classification may use accuracy or probability-sensitive metrics; grouping may use a geometric or external utility criterion. The loss optimized during fitting need not be the only evaluation metric. We next separate the data used for fitting, choosing and finally evaluating a procedure in III-04.

Check your understanding

Labels 0 and 1 denote two email categories. What is the task?
A target is a measured proportion that may be 0.4. What is the task?
A dataset has labels, but the chosen goal groups rows using only features. Which description applies?
What is missing from a purely unsupervised grouping dataset?
Can the values [0, 1, 0] alone determine the learning task?

Checkpoints

You can state whether the goal uses supervision, decide whether its target is an amount or a category, and explain why target codes alone are insufficient. A learning problem starts with meaning and available information; array storage follows that specification.