Loading Built-In Datasets in scikit-learn
Synthetic datasets are made-up datasets, designed on purpose to highlight particular aspects of an algorithm, and they can be small or large.
Why Algorithms Need Test Data
When you learn a machine learning algorithm, you need data to test it on. The datasets used for this purpose come in two broad kinds. Some are small and synthetic, which means they are made up. Others are large and come from real-world applications. Both kinds have a role, and understanding why each one exists makes the rest of the algorithm material easier to follow.
What do you think happens?
The forge dataset is loaded into a variable X and you run print(X.shape). Before reading on, predict what gets printed. How many rows and how many columns do you expect?
Reveal answer
(26, 2)
The forge dataset has 26 data points, each stored as one row of X, and 2 features, each stored as one column. X.shape reports rows first and columns second, so the output is (26, 2).
Synthetic Versus Real-World Data
A synthetic dataset is made up on purpose. Its designer chooses its shape so that it highlights one particular aspect of an algorithm. Synthetic datasets can be small or large, but their defining feature is that someone constructed them to illustrate a behavior.
A real-world dataset works the other way around. It is collected from an application that exists outside the textbook, so its structure is whatever the real process produced. Nobody arranged its features to make one algorithm look clear. The Wisconsin Breast Cancer dataset, often called cancer for short, is an example. It records clinical measurements of breast cancer tumors, and each tumor is labeled as benign, meaning harmless, or malignant, meaning cancerous. The task is to learn to predict whether a tumor is malignant from measurements of the tissue.
| Property | Synthetic dataset | Real-world dataset |
|---|---|---|
| Origin | Made up on purpose by a designer | Collected from a real application |
| Shape | Chosen to highlight one behavior | Whatever the real process produced |
| Typical size | Can be small or large | Often large |
| Example in this article | forge and wave | Wisconsin Breast Cancer (cancer) |
| Best used for | Building understanding of a specific behavior | Testing that understanding against a real application |
Synthetic and real-world datasets serve complementary roles.
Neither kind replaces the other. The synthetic sets make a specific behavior easy to see, and the real-world sets show whether that behavior appears in practice.
Reading the Shape of the Forge Dataset
The first dataset this course uses is the forge dataset. It is a synthetic two-class classification dataset with two features. The data is split into two parts. X holds the data points, and y holds the class labels. The printed shape is the fastest way to check what a dataset contains.
(26, 2)- X is a table: each row is one data point and each column is one feature
- The first number is the count of rows, which is 26 data points
- The second number is the count of columns, which is 2 features
Because the labels in y are kept separately, with one label per point, they line up with the rows of X. Row 0 of X and the first entry of y describe the same data point. Reading the shape therefore tells you the size of both parts at once: 26 points, each with 2 feature values, and 26 labels.
From Rows to Points on a Scatter Plot
Printing a shape tells you how big the dataset is, but not what it looks like. A scatter plot fills that gap. In the forge plot, the first feature sits on the horizontal axis and the second feature sits on the vertical axis. Each data point becomes one dot, placed at the coordinates given by its two feature values.
The color and shape of each dot show the point's class, so you can see at a glance which points belong to Class 0 and which belong to Class 1. This is the main reason scatter plots are useful for classification data. They let you check whether the classes separate, overlap, or are mixed together. Patterns in the dots, not in the printed numbers, reveal how the features relate to the classes.
The Wave Dataset and Feature-Versus-Target Plots
The forge dataset answers a classification question: which class does a point belong to? For regression algorithms, the book uses a different synthetic dataset called wave. It has a single input feature and a continuous target variable, which is the response the algorithm tries to model. The code creates 40 points, and the plot puts the feature on the horizontal axis and the target on the vertical axis.
The target is plotted as a continuous quantity, not as a set of colored classes. Each dot still corresponds to one row: its horizontal position is its feature value, and its vertical position is its target value. Because the target is numeric, the plot shows how the response changes as the feature changes.
Predicting the shape of the wave data
The wave dataset has 40 points, one input feature, and one continuous target. What shape would X have, and what would y contain?
- 1Count the data points
The dataset is created with 40 points, so X has 40 rows.
- 2Count the features
The wave dataset has a single input feature, so X has 1 column.
- 3Describe the target
y holds one continuous numeric value per point, so it also has 40 entries, one per row of X.
X has shape (40, 1), and y holds 40 continuous target values. Compared with the forge shape (26, 2), the wave data has more points but only one feature.
Both datasets come from the same mglearn module and both are generated by a make function, but their roles differ. The forge data asks which class a point belongs to. The wave data asks what numeric value goes with each feature value.
Why Small Datasets Can Mislead
Simple datasets are chosen because they are easy to see. A printed page has two dimensions, so a dataset with two features can be drawn directly, with one feature per axis. Data with many more features is hard to show at all. Datasets with few features are called low-dimensional, and datasets with many features are called high-dimensional.
Mistakes Learners Make with Dataset Structure
Common mistake Reading the shape numbers in the wrong order
What it looks likeReading (26, 2) as 26 features and 2 data points.
Why it failsX.shape reports rows first. Rows are data points and columns are features.
Do this insteadRead the first number as rows (data points) and the second as columns (features).
Common mistake Thinking the labels are stored as extra columns of X
What it looks likeExpecting the forge shape to include a third column for the class.
Why it failsThe labels in y are kept separately, one per point, so X keeps only the feature columns.
Do this insteadMatch each row of X with the same position in y to find its class.
Common mistake Treating a scatter plot's colors as features
What it looks likeAssuming the color of each dot is a third feature.
Why it failsIn the forge plot, color and shape show the class. The axes carry the two feature values.
Do this insteadUse the horizontal and vertical positions for features and the color or shape for the class.
Common mistake Assuming a 2D picture generalizes to any dataset
What it looks likeConcluding that an algorithm will behave the same way on a dataset with fifty features because it looked clean on two.
Why it failsIntuition from low-dimensional data may not hold in high-dimensional data.
Do this insteadTreat small-dataset lessons as a starting point and test them on data with more features.
Practice Reading a Dataset Before Plotting It
A dataset loads with X.shape equal to (40, 1) and y containing continuous numbers. Without running any plot, describe how many points the dataset has, how many features each point has, what kind of target it has, and whether it suits a classification or a regression algorithm. Then say what a feature-versus-target scatter plot of this data would put on each axis.
Hints
- The first number in the shape counts rows, and rows are data points.
- The second number counts columns, and columns are features.
- A continuous target means a numeric response, not a set of colored classes.
Key Takeaways
- Synthetic datasets are made up on purpose so that they highlight a particular aspect of an algorithm, while real-world datasets are collected from applications and test whether a behavior appears in practice.
- X.shape reports rows as data points and columns as features; the forge dataset's shape (26, 2) means 26 points with 2 features.
- Scatter plots show each data point as one dot positioned by its feature values, and colors or shapes reveal class membership; feature-versus-target plots show how a continuous target changes with a feature.
- Intuition built on low-dimensional datasets, which can be drawn directly, may not hold for high-dimensional datasets, so small examples should be used with that limit in mind.