What Is a Dataset?
After this lesson, you will be able to:
- Say what a row and a column are in a dataset, using a table you can see
- Name the label (the column you want to guess) and the features (the columns you guess from)
- Tell number columns from category columns
- Make a first guess from a dataset without any learning, and say why a better guess uses the features
#A Dataset Is a Table
Here is a made-up table of eight houses. The numbers are invented for teaching and do not describe any real town.
| house | size (sq m) | bedrooms | area | price (thousands) |
|---|---|---|---|---|
| 1 | 50 | 1 | North | 120 |
| 2 | 65 | 2 | North | 150 |
| 3 | 80 | 2 | South | 170 |
| 4 | 80 | 3 | North | 190 |
| 5 | 100 | 3 | South | 220 |
| 6 | 120 | 4 | South | 260 |
| 7 | 70 | 2 | South | 155 |
| 8 | 90 | 3 | North | 200 |
A table has 200 rows and 6 columns. What does one row stand for?
In one sentence: a dataset is a table where each row is one example and each column is one kind of fact about it.
#The Column You Want to Guess
Now ask a useful question. Suppose a new house is for sale and nobody has priced it. You know its size, its bedrooms and its area. Can you guess its price from the eight houses you already know about?
| size | bedrooms | area | price | |
|---|---|---|---|---|
| Role | feature | feature | feature | label |
| Known for the new house? | yes | yes | yes | no, this is the question |
Which column is the label depends on your question, not on the table. If your question were "which area is this house in?", the label would be area, and price would be one of the features. The same table can serve many questions.
In one sentence: the label is the column you want to guess, and the features are the columns you guess it from.
#Look at a Column Before You Trust It
Below is a ready-made table of 50 people with an age, an income and a score. It is not the house table; it is a bigger practice table so that the shapes are easy to see.
Do: On the Histogram tab, choose Age and then Income, and move the Bins slider up and down.Notice: Each column has its own shape. Some bars are tall and some are short, and the picture changes when you use more or fewer bins.Why: A histogram counts how many rows fall into each range of values. Looking at the shape tells you what is common and what is rare before you build anything. The table is a drawn, made-up sample.
In one sentence: draw a picture of a column first, because a shape shows in a second what a list of numbers hides.
#Two Kinds of Column
This matters because a model can only do arithmetic on numbers. A category has to be changed into numbers before a model can use it, and doing that badly can mislead the model. A later lesson in this track is all about that change. For now, just sort every column you meet into one of two bins.
Which column of the house table is a category column?
A small trap hides here. Some columns that look like numbers are really names. A postal code of 500001 is not "bigger" than 400001 in any useful way, and adding two postal codes means nothing. Ask yourself: does adding or averaging this column make sense? If not, it is a category.
In one sentence: number columns can be added and averaged, category columns hold names, and some number-looking columns are really names.
#Your First Guess Without Learning
Before any model, try the simplest guess you can think of. Hand trace it on the house table.
Notice what just happened. A guess that uses the features beat a guess that does not. That is the entire reason features exist. A learning method is a more careful, more automatic way of doing what Guess 2 does by hand.
Now run the same thing in code. You can read it line by line: each dictionary is a row, each key is a column name.
Do: Run the cell once. Then changenew_sizeto 60 and run it again.Notice: The first run prints rows: 8, the four column names, the label price, an average of 183.125, and a guess of 200 from the house of size 90. With size 60 the closest house changes to size 65 and the guess becomes 150.Why: The plain average never changes, because it ignores the features. The closest-house guess moves with the new house, because it reads the size column. This is a toy rule, not a trained model, and it uses only one feature.
In one sentence: a guess that reads the features can beat a guess that ignores them, and learning is a careful way of finding that guess.
#When a Dataset Misleads
A dataset can be tidy and still be a poor picture of the world. Four questions are worth asking about any table before you trust it.
- Is it big enough? Eight houses cannot tell you about a whole city.
- Does it cover the cases you care about? If every house in the table is small, the table says nothing useful about a large one.
- Is anything missing or wrong? An empty cell, a size of -5, or the same house written twice all quietly bend the answer.
- Who collected it and why? A table of houses that were listed online leaves out houses that were never listed.
You do not need to fix any of these today. You only need the habit of asking. The next lesson, Reading a Table with Python, shows how to count rows, spot empty cells and ask questions of a table. Later lessons in this track fix each problem properly.
In one sentence: before trusting a dataset, ask whether it is big enough, covers your cases, is free of bad rows, and was collected fairly.
A table of facts in which each line describes one example.
One line of the table. It is one example, such as one house.
One vertical strip of the table. It is one kind of fact, such as size.
The column you want to guess, such as price. It is not known for a new example.
A column you use to make the guess, such as size or bedrooms.
Learning from rows where the label is already known, like a teacher writing the right answer next to every example.
A column whose values you can add and average, such as size.
A column whose values are names from a short list, such as North and South.
#Key Takeaways
- A dataset is a table: each row is one example and each column is one kind of fact
- The label is the column you want to guess; the features are the columns you guess it from
- Never give the label to the guesser as an input, or it only reads the answer
- Sort every column into number or category, and watch for number-looking names such as postal codes
- A guess that reads the features can beat a plain average, and a picture of a column is the fastest way to know it
#Quick Check
A table lists 500 customers, with columns for age, city and whether each one cancelled. You want to guess who will cancel. Which column is the label?