Overview

2 Types of machine learning

This chapter introduces machine learning as a way for computers to make decisions from experience, then organizes the field around the kind of information available and the goal of the task. A key distinction is between labeled and unlabeled data: labeled datasets include a target (the value or category to predict), while unlabeled datasets do not. Building on this, the chapter presents three major families—supervised learning, unsupervised learning, and reinforcement learning—and illustrates how seemingly different applications (pricing houses, filtering spam, grouping users, or playing games) can be addressed with related techniques once the data and objective are clarified.

Supervised learning operates on labeled data and aims to predict the label for new, unseen examples. Labels can be numerical (leading to regression) or categorical (leading to classification). Regression tackles problems like estimating house prices, stock values, or patient recovery times, while classification assigns inputs to categories, such as spam versus ham, sentiment polarity, image classes, or click/no-click outcomes. The supervised workflow mirrors a remember–formulate–predict pattern: learn from past examples, capture patterns in a model, and use that model to produce predictions for new inputs. Because of its practicality and prevalence, supervised learning is the central focus of the book.

Unsupervised learning extracts structure from unlabeled data. Clustering groups similar items (useful for market segmentation, organizing emails, or medical image partitioning), and dimensionality reduction compresses features into lower-dimensional representations that preserve essential information, often as a preprocessing step. The chapter also highlights matrix factorization and singular value decomposition for jointly simplifying rows and columns, enabling applications like recommendations and image compression. Generative learning creates new samples resembling the source data, powering realistic images, audio, and text. Finally, reinforcement learning departs from static datasets: an agent learns to act in an environment by maximizing rewards, underpinning advances in games, robotics, and autonomous driving.

Labeled data is data that comes with a tag, or label. That label can be a type or a number. Unlabeled data is data that comes with no tag. The dataset on the left is labeled, and the label is the type of pet (dog/cat). The dataset in the middle is also labeled, and the label is the weight of the pet (in pounds). The dataset on the right is unlabeled.
A supervised learning model predicts the label of a new data point. In this case, the data point corresponds to a dog, and the supervised learning algorithm is trained to predict that this data point does, indeed, correspond to a dog.
A supervised learning model follows the remember-formulate-predict framework from chapter 1. First, it remembers the dataset. Then, it formulates rules for what would constitute a dog and a cat. Finally, it predicts whether a new data point is a dog or a cat.
An unsupervised learning algorithm can still extract information from data. For example, it can group similar elements together.
A plot of the email dataset. The horizontal axis corresponds to the size of the email and the vertical axis to the number of recipients. We can see three well-defined clusters in this dataset.
We can cluster the emails into three categories based on size and number of recipients.
Dimensionality reduction algorithms help us simplify our data. On the left, we have a housing dataset with many features. We can use dimensionality reduction to reduce the number of features in the dataset without losing much information and obtain the dataset on the right.
How to imagine higher dimensional spaces: One dimension is like a street, in which each house only has one number. Two dimensions is like a flat city, in which each address has two numbers, a street and an avenue. Three dimensions is like a city with buildings, in which each address has three numbers: a street, an avenue, and a floor. Four dimensions is like an imaginary place in which each address has four numbers. We can imagine higher dimensions as another imaginary city in which addresses have as many coordinates as we need.
Clustering can be used to simplify our data by reducing the number of rows in our dataset by grouping several rows into one.
Dimensionality reduction can be used to simplify our data by reducing the number of columns in our dataset.
A grid world in which our agent is a robot. The goal of the robot is to find the treasure chest, while avoiding the dragon. The mountain represents a place through which the robot can’t pass.
Here is a path that the robot could take to find the treasure chest.

FAQ

What are the three main types of machine learning?Supervised learning, unsupervised learning, and reinforcement learning. Supervised uses labeled data to predict targets, unsupervised finds structure in unlabeled data, and reinforcement learning trains an agent to act in an environment using rewards and penalties.
What is the difference between labeled and unlabeled data?Labeled data includes a target (label) you want a model to predict, such as “spam/ham” or a numeric price. Unlabeled data has no such target; the goal is to discover patterns or simplify the data without predicting a predefined label.
What are features and labels in a dataset?Features are the descriptive variables (columns) that characterize each data point (row), such as size, number of rooms, or words in an email. A label (or target) is the specific feature you want to predict, like house price (number) or email type (spam/ham).
How do regression and classification differ?Both are supervised learning. Regression predicts numeric values (e.g., house price or weight), while classification predicts a category from a finite set (e.g., cat vs. dog, spam vs. ham).
Which applications call for regression versus classification?- Regression: price forecasting, expected watch time, recovery time, or stock price prediction.
- Classification: spam detection, image recognition (cat/dog), sentiment (positive/negative), click prediction (click/no click).
What is unsupervised learning and what are its main branches?Unsupervised learning works with unlabeled data to uncover structure or reduce complexity. Its main branches are clustering (group similar items), dimensionality reduction (represent data with fewer features), and generative modeling (create new samples resembling the data).
How do clustering algorithms group data?They partition data points into groups so items in the same group are more similar to each other than to those in other groups. Examples include grouping emails by size/recipients or customers by behavior; common methods are k-means, hierarchical clustering, DBSCAN, and Gaussian mixture models.
What is dimensionality reduction and why is it called “dimensionality” reduction?It compresses data into fewer features while preserving most information (e.g., combining related house attributes into broader “size” or “neighborhood” factors). “Dimension” refers to the number of features; reducing dimensions means fewer columns in the dataset.
What roles do matrix factorization and SVD play in unsupervised learning?They decompose a large data matrix into smaller factors, effectively reducing both rows and columns. Matrix factorization powers recommender systems (e.g., user–movie ratings), while singular value decomposition (SVD) is widely used for tasks like image compression.
What is reinforcement learning and where is it used?It trains an agent to make sequential decisions in an environment to maximize cumulative reward (e.g., reaching a goal while avoiding penalties). Applications include game-playing (Go, chess, Atari), robotics (manipulation, navigation), and self-driving tasks like path planning.

pro $24.99 per month

  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose one free eBook per month to keep
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime

lite $19.99 per month

  • access to all Manning books, including MEAPs!

team

5, 10 or 20 seats+ for your team - learn more


choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Grokking Machine Learning, Second Edition ebook for free
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Grokking Machine Learning, Second Edition ebook for free