Supervised, unsupervised and reinforcement learning

Three ways a system can learn

In the house-price introduction, a model learned from past sales whose prices were already known. That is one learning setup, but not every task supplies a correct answer for each example. Sometimes we want to discover groups; sometimes a system must learn which actions to take.

The useful distinction is what information guides learning. Supervised learning uses examples with known targets. Unsupervised learning finds structure without supplied target labels for that task. Reinforcement learning uses the consequences of actions and reward feedback to learn a way of acting.

These are learning setups, not levels from beginner to advanced. None means “no people involved,” and none is automatically the best choice. We will compare house-price estimation, grouping home listings and a small navigation task before choosing a method.

What you’ll learn

  • Identify whether a task supplies targets, similarity structure or action rewards.
  • Distinguish predicting a quantity from predicting a category.
  • Explain why a discovered cluster is not automatically a correct category.
  • Trace action, feedback and a learned action value in a small reinforcement example.
  • Choose a learning setup from the task and available evidence.

Look at the information available

Supervised

Predict a known kind of outcome

Training information
Areas paired with actual sale prices
What guides learning
Difference from the known prices
New output
Estimated sale price

Targets are available during training.

Unsupervised

Explore structure in the records

Training information
Listing areas and bedroom counts
What guides learning
Similarity under the chosen measurements
New output
Groups of similar listings

No supplied correct group for each listing.

Reinforcement

Learn which action to take

Training information
Position, action, next position and reward
What guides learning
Reward accumulated through interaction
New output
An action choice for the current situation

Actions affect what happens next.

These are alternatives for different tasks, not three stages every model passes through.

Supervised learning: examples with known targets

Suppose you have past sales with floor areas of 50, 75, 100 and 125 m² and actual prices of $150,000, $200,000, $250,000 and $300,000. Each area is an input feature; its matching price is the target. A training procedure fits a relationship using both. For a new house, only the area is supplied to request an estimate.

The word “supervised” does not mean someone watches every prediction. It means the training examples supply the outcomes that guide fitting. Those outcomes may come from recorded sales, measurements or human annotation. A label is the known target attached to an example; it is not necessarily a word or category.

The learned relationship must be checked on separate examples. Incorrect prices, mismatched rows or records from an unrelated market can teach an unreliable relationship even though the training procedure runs successfully. Review separating training from test data before judging usefulness.

Regression predicts quantities; classification predicts categories

A supervised task is regression when its target is a quantity: price, travel duration or electricity use. It is classification when the target is membership in a category: spam or ordinary email, for example. Both use known targets during training; the kind of desired output differs.

In a listing service, predicting a sale price is regression. Predicting whether a listing is an apartment or a detached house from suitable records is classification. Category names are not numbers to average, even when software encodes them as 0 and 1. Some classifiers produce probabilities, but those estimates also need evaluation.

Keep prediction distinct from an exact policy. If a known advertised price is below a service’s budget limit, an ordinary comparison can label it within budget. Training a classifier to recreate that already specified comparison adds unnecessary complexity.

Same learning setup, different target

Regression

Estimate sale price

Inputs
Floor area and other relevant measurements
Known training target
Actual sale price in dollars
Output
A numerical price estimate

A numerical error can compare predicted and actual prices.

Classification

Identify a listing category

Inputs
Relevant listing measurements
Known training target
Apartment or detached house
Output
A category or class probabilities

Check wrong categories, not the arithmetic average of category codes.

Choose from the output the application needs, not from whether its input happens to contain numbers.

Run a supervised price predictor

Prepare and run

Use the Python environment with NumPy and scikit-learn. These fictional records repeat the introduction’s complete dataset. No file or download is needed.

Python · complete runnable example

import numpy as np
from sklearn.linear_model import LinearRegression

areas = np.array([[50], [75], [100], [125]])
known_prices = np.array([150000, 200000, 250000, 300000])
model = LinearRegression().fit(areas, known_prices)
print("Supervised price estimate:", round(model.predict([[90]])[0]))

Expected output

Supervised price estimate: 230000

Areas is a four-row, one-column input table. Known_prices supplies one target for each row in the same order. Fit uses both to learn the line. Predict receives one new row, [[90]], and returns an array; [0] selects its first estimate. Round displays a whole-dollar number.

This is supervised regression because known prices guide training and the result is a quantity. It does not become unsupervised when predict receives only the new area: the learning setup is determined by how the model was trained.

Unsupervised learning: discover structure without target labels

Now change the question. A service has home listings with areas and bedroom counts, but no “correct group” recorded for each listing. It wants to explore whether similar homes form useful groups. This is a clustering task, one kind of unsupervised learning.

A clustering method groups records according to its chosen representation and similarity rule. For example, nearby numerical measurements may end up together. It does not discover guaranteed categories such as “good investment” or “ideal family home.” People need to inspect what the groups actually mean and whether they help the application.

Unsupervised does not mean every column in the source file lacks a label or heading. It means the learning procedure does not receive the task’s correct target labels. Nor does it mean random learning: people still choose the features, method and settings.

Other unsupervised methods produce a smaller representation of data rather than groups. The PCA lesson covers that different purpose.

Run a grouping example without known groups

Prepare and run

Use the same Python environment. This simplified example uses only floor area so you can inspect what similarity means. Each inner array is one listing with one feature. There are no supplied group labels.

Python · complete runnable example

import numpy as np
from sklearn.cluster import KMeans

# Fictional floor areas; no supplied group labels or sale prices.
areas = np.array([[45], [50], [120], [125]])
model = KMeans(n_clusters=2, random_state=0, n_init=10)
groups = model.fit_predict(areas)
print("45 and 50 grouped together:", bool(groups[0] == groups[1]))
print("120 and 125 grouped together:", bool(groups[2] == groups[3]))
print("The pairs are separate:", bool(groups[0] != groups[2]))

Expected output

45 and 50 grouped together: True
120 and 125 grouped together: True
The pairs are separate: True

We ask KMeans for two clusters; the algorithm does not independently decide that two is the ideal number. It groups the nearby 45 and 50 values and separately groups 120 and 125. The comparisons inspect membership rather than relying on cluster numbers: swapping names 0 and 1 would not change the grouping.

Random_state fixes the random seed for repeatable initialization, and n_init=10 requests ten initializations. These settings help make this teaching example repeatable; they do not make the groups meaningful or prove two is best. Multiple features with different units would also require attention to feature scaling.

A person could later call the groups “smaller” and “larger.” That interpretation does not retroactively turn clustering into supervised training. Training a later predictor from human-assigned labels would be a different stage.

Membership matters more than the group number

Nearby areas

45 m²50 m²

Nearby areas

120 m²125 m²
Each pair contains nearby measurements. Giving the first group the number 1 instead of 0 would leave the membership unchanged. The gap between pairs—not a supplied group name—explains this example’s grouping.

Reinforcement learning: actions change the next situation

Imagine a delivery robot learning how to reach a destination. It observes its current situation, chooses an action, then experiences a new situation and feedback. Moving can change the choices available next. This action-and-consequence loop differs from estimating a price from a fixed input row.

The agent is the decision-making learner. The environment is the system it interacts with. The state describes the situation used for choosing an action. A reward is a numerical feedback signal. A policy is a rule or learned strategy for choosing actions from situations.

The goal typically concerns reward accumulated over a sequence. A move with a small immediate cost may still be worthwhile if it reaches a useful destination later. Learning may involve exploration, trying actions to gather information, and exploitation, using what has been learned to choose a promising action.

ObserveAt the corridor entrance
ActMove toward the goal
Receive feedbackGoal reached; reward +1
Update the strategyUse the experience for later decisions

Reward is not a supplied correct answer for every possible action. It tells the learner how the experienced outcome was scored. The environment and reward design can be simulated, and a learned policy can later run without continuing to learn.

Trace a tiny action-and-reward learner

Prepare and run

This complete program uses standard Python. Every episode starts at one entrance and ends after one action. Waiting receives −1; moving reaches the goal and receives +1. The fixed exploration schedule is supplied for teaching. This is a one-step action-value demonstration, not a general robot, a multi-step reinforcement algorithm or a production safety system.

Python · complete runnable example

# A one-state, one-step teaching environment, not robot control.
actions = ["wait", "move"]
values = {action: 0.0 for action in actions}
learning_rate = 0.5

def step(action):
    if action == "move":
        return "goal", 1.0, True
    return "entrance", -1.0, True

# Try each action twice so this tiny demonstration gathers both outcomes.
for action in ["wait", "move", "wait", "move"]:
    next_state, reward, finished = step(action)
    values[action] += learning_rate * (reward - values[action])
    print(action, "reward", reward, "value", values[action])

chosen = max(actions, key=lambda action: values[action])
print("Learned choice:", chosen)

Expected output

wait reward -1.0 value -0.5
move reward 1.0 value 0.5
wait reward -1.0 value -0.75
move reward 1.0 value 0.75
Learned choice: move

The dictionary stores a learned value for each action, initially zero. Step is the environment: it returns the next state, reward and whether this one-step episode has finished. The update moves an action’s value halfway toward the reward it just received. For the first move, 0 + 0.5 × (1 − 0) = 0.5. For the second move, 0.5 + 0.5 × (1 − 0.5) = 0.75.

After both actions have been tried twice, max chooses move because 0.75 exceeds −0.75. Each value estimates that action’s immediate reward in this fixed task. Since every episode ends immediately, there is no future reward term. Next_state and finished document the environment interface; this minimal program does not use them to train a navigation path.

A multi-step system must also account for future outcomes, explore appropriately and define safe interaction. The Gymnasium environment guide shows the richer reset/step interaction and distinguishes termination from time limits.

Choose from the task—not the algorithm’s name

Start by writing the output you need. If it is a numerical price or a category, ask whether representative examples have known targets. If the purpose is discovering groups without correct group labels, ask what similarity would be meaningful. If decisions change future observations, ask whether an action-and-reward environment is really needed.

A stream of live data is not automatically reinforcement learning. A price predictor receiving frequent new listings is still supervised if it is trained on known prices. Feedback arriving later does not by itself make a task reinforcement learning; the role of action choices and their effects matters.

A classification system can be trained from a fixed labelled table, while an agent can learn from previously recorded interactions as well as fresh ones. The core reinforcement distinction is the action/outcome/reward setup, not a requirement that every experiment control a physical robot in real time.

Sometimes an ordinary rule, a search procedure or a control method already solves the task. A corridor with a known safe route does not require reinforcement learning simply because a robot is involved. Check the simplest suitable approach first.

Choose a setup and explain your choice

Your tasks: (1) You have past areas paired with sale prices and need a price estimate. (2) You have areas only and want to explore groups. (3) A learner tries actions in a simulator and uses the resulting rewards to improve its choices. What setup fits each, and what information makes the difference?

Worked answer

(1) Supervised regression: known sale prices supply targets and the desired output is a quantity. (2) Unsupervised clustering: the grouping stage has no supplied correct cluster for each listing. (3) Reinforcement learning: action choices affect outcomes, and reward guides the strategy.

One more distinction: after clustering, people name the groups. Was the original grouping supervised? No. Naming results afterward does not change the information used to fit them. A later category predictor trained on those named examples would be supervised.

Trace the one-step learner: a move value is 0.5, its next reward is 1 and the learning rate is 0.5. The next value is 0.5 + 0.5 × (1 − 0.5) = 0.75. The reward is not copied into the value all at once; this update moves partway toward it.

Limits, reward design and other learning setups

Known labels can be mistaken, incomplete or unrepresentative. Clusters can reflect the chosen units or irrelevant measurements rather than useful groups. Rewards can encourage behavior the designer did not intend: rewarding only speed may encourage unsafe shortcuts. A high measured result is not enough without inspecting what success actually means.

Semi-supervised learning combines labelled and unlabelled examples for a learning task. Self-supervised learning constructs a training target from data itself—for example, hiding part of a sentence and learning to predict it. These are useful additional setups, not reasons to call every task one of three perfectly isolated boxes.

The types can be combined within a larger application. A system might use unsupervised exploration, supervised predictions and separate decision logic. Do not infer that every prediction system has an agent, or that every grouped record has a verified category.

Evaluate according to the job: numerical errors for price estimates, category-specific mistakes for classification, meaningful group usefulness for clustering, and accumulated outcomes plus safety checks for action systems. This lesson explains the setup; the later lessons develop algorithms and evaluation methods.

Quiz: quantity or category?

A model learns apartment versus detached-house categories from labelled listings. What is this task?
Choose one answer. You can try again.

Answer and explanation

Supervised classification.

The examples contain known categories, and the requested output is category membership rather than a numerical quantity.

Quiz: what does a cluster establish?

A method groups listings by area without known group labels. People later name the groups. Which statement is sound?
Choose one answer. You can try again.

Answer and explanation

The grouping was unsupervised and its usefulness still needs review.

The procedure had no supplied correct group labels. The resulting groups need interpretation and evaluation for the proposed use.

Quiz: reward versus the intended goal

A robot earns rewards only for arriving quickly. Why might this be insufficient?
Choose one answer. You can try again.

Answer and explanation

The reward may favor unsafe shortcuts that the designer did not intend.

Optimizing an incomplete reward can encourage undesirable behavior. The learning setup needs safety constraints and an appropriate evaluation.

Recap: identify what guides learning

Supervised: fit from inputs paired with known targets. Regression predicts quantities; classification predicts categories. Unsupervised: explore structure without supplied target labels for that task. Reinforcement: learn action choices from experienced outcomes and rewards, often across a sequence.

The same application domain can support different tasks. Houses do not imply regression, and robots do not imply reinforcement learning. State the job, identify the available learning signal and explain how success will be checked.

Transfer the idea: predicting journey minutes from completed trips is supervised regression. Grouping similar trip patterns without group labels is unsupervised. Learning which route actions to take from their consequences and accumulated rewards can be reinforcement learning. An exact known routing rule may require no learning at all.

Technical references: scikit-learn supervised learning, clustering documentation, and Gymnasium environment interactions.

Reaching the recap and completing the quizzes are separate milestones.

    Next lesson: Machine learning in everyday applications →