• Foundation
  • About 15 min
  • 5 practice questions

Data and features: examples, labels, data types and clean data

Pick out the examples, features and label in a table of data, tell numerical from categorical data, and clean a small dataset by fixing errors, removing duplicates and handling missing values.

If something looks wrong, please tell us.

By the end of this lesson you can

  • Name the examples (rows), the features and the label in a table of data.
  • Tell numerical, categorical and unstructured data apart, and say how categories are turned into numbers.
  • Clean a small dataset: fix errors, remove duplicates and fill missing values sensibly.

Machine learning (ML) is the part of Artificial Intelligence in which a computer learns patterns from examples instead of following rules written by hand. Everything it learns comes from data, so the data is where every ML project starts and where most of them go wrong. This lesson explains them with small tables you can work through by hand.

Rows, features and labels

ML data is usually arranged like a spreadsheet. Each row is one example (also called a record or instance): one mango, one loan application, one email. Each column describes the examples. The columns the model uses as inputs are the features. The column holding the answer we want the model to predict is the label (or target). A collection of examples is a dataset.

A dataset

  • Rows
    • Each row is one example (record or instance)
    • One mango, one loan application, one email
  • Features
    • The columns the model uses as inputs
  • Label
    • The column holding the answer to predict
    • Also called the target

Worked example 1: reading a dataset

A fruit seller in Nashik wants a model that tells whether a mango is ripe. She records four mangoes:

A tiny labelled dataset
MangoWeight (g)Colour score (1-10)Softness (1-5)Ripe? (label)
125084Yes
218031No
323074Yes
421042No

Working: there are 4 rows, so 4 examples. Weight, colour score and softness are the inputs, so there are 3 features. 'Ripe?' is the answer to be predicted, so it is the label. The 'Mango' column is only a serial number and should not be used as a feature, because it says nothing about ripeness. With a few hundred such rows, a model can look at a new mango's three features and predict the label. Data that has a label column is called labelled; data without one is unlabelled.

Types of data

Common kinds of data
TypeWhat it looks likeExamples
NumericalNumbers that can be measured or countedWeight in grams, monthly rent, number of rooms
CategoricalNames of groups with no orderState, blood group, payment mode (UPI, cash, card)
OrdinalCategories with a natural orderSmall, medium, large; class 8, class 10, class 12
UnstructuredNot in neat columnsPhotos, voice recordings, free text such as complaints

Models calculate with numbers, so categories must be converted. Giving payment modes the codes UPI = 1, cash = 2, card = 3 is risky: the model may treat card as 'three times UPI', an order that does not exist. The usual fix is one-hot encoding: make one yes/no column for each category, so a UPI payment becomes UPI = 1, cash = 0, card = 0. Ordinal data can keep numbers in order (small = 1, medium = 2, large = 3) because the order is real. Photos, sound and text are also turned into numbers, for example the brightness of each pixel.

Cleaning the data

Real data is messy. Before any learning, it is cleaned in a few standard steps:

Cleaning data before learning

  1. Remove duplicates The same entry twice would count double.
  2. Fix wrong values Impossible or inconsistent values, such as an age of 205.
  3. Handle missing values Drop the row, or fill the gap with the mean, median or most common value.
  4. Check the labels A wrong label teaches the wrong lesson.
  5. Record every change So the same cleaning can be repeated on new data.
  1. Remove duplicates: the same application entered twice would count double.
  2. Fix impossible or inconsistent values: an age of 205, 'Lucknow', 'lucknow' and 'LKO' written for one city, or weights mixed in grams and kilograms.
  3. Handle missing values: drop the row if only a few rows are affected and data is plentiful, or fill the gap. Numbers are often filled with the mean or the median of the column, and categories with the most common value.
  4. Check the labels: a wrong label teaches the model the wrong lesson.
  5. Record every change, so that the same cleaning can be repeated on new data.

Worked example 2: filling a missing value

Monthly electricity units for five houses are 120, 150, (missing), 130 and 600. The 600 belongs to a house running a flour mill. Mean of the four known values = (120 + 150 + 130 + 600) ÷ 4 = 1,000 ÷ 4 = 250. Median: sort them as 120, 130, 150, 600; the middle two are 130 and 150, so the median = (130 + 150) ÷ 2 = 140. The single large value pulls the mean up to 250, higher than three of the four houses, while the median of 140 is typical. When a column has extreme values, the median is usually the safer fill.

Why data quality decides results

A model can only learn what its data shows. If a loan dataset contains only city applicants, the model has never seen rural applicants and may judge them badly. If many labels are wrong, the model learns the mistakes. If the data is old, the model learns yesterday's patterns. More data helps only when it is correct and represents the people and situations the model will meet.

Garbage in, garbage out: a model can be no better than the data it learns from.

Key takeaways: a row is an example, the inputs are features and the answer is the label. Categories are converted to numbers, usually by one-hot encoding, and ordinal data keeps its order. Clean data before learning: remove duplicates, fix errors, handle missing values and check labels. The median is a safer fill than the mean when extreme values exist. Data that is wrong or unrepresentative produces a model that is wrong or unfair.

Check your understanding

  1. 1. A model predicts the selling price of used cars from their age, kilometres driven and engine size. What is the selling price here?

    1. A feature
    2. An example
    3. The label
    4. A duplicate
    Show answer

    Answer: C. The selling price is the answer the model must predict, so it is the label (target). Age, kilometres driven and engine size are the features used as inputs, and each car is one example.

  2. 2. A dataset has 1,200 rows and 9 columns. One column is the label and all the others are used as inputs. How many features are there?

    1. 8
    2. 9
    3. 1,200
    4. 10
    Show answer

    Answer: A. Each row is an example, so there are 1,200 examples. Of the 9 columns, 1 is the label, so the number of features = 9 − 1 = 8.

  3. 3. Which of these is categorical data?

    1. Height in centimetres
    2. Monthly salary in rupees
    3. Number of rooms in a flat
    4. Blood group
    Show answer

    Answer: D. Blood group names a group (A, B, AB, O) with no order or size, so it is categorical. Height, salary and number of rooms are numbers that are measured or counted, so they are numerical.

  4. 4. A column of ages has one missing value. The known values are 18, 20, 22, 24 and 96. What is the median of the known values, which is a sensible value to fill the gap?

    1. 36
    2. 22
    3. 20
    4. 24
    Show answer

    Answer: B. Sort the known values: 18, 20, 22, 24, 96. With five values the middle one is the third, so the median is 22. The mean would be 180 ÷ 5 = 36, pulled up by the extreme value 96, which is why the median is the safer fill here.

  5. 5. Why is it risky to code payment modes as UPI = 1, cash = 2 and card = 3 before training?

    1. Models cannot read numbers
    2. The model may treat the codes as an order or size that does not exist
    3. It deletes the label column
    4. It makes the dataset smaller
    Show answer

    Answer: B. The numbers suggest that card is larger than cash and cash larger than UPI, which means nothing. One-hot encoding avoids this by giving each payment mode its own yes/no column.

Privacy · Terms · Refunds · Delivery