Data is the raw material of learning. Understanding how a dataset is organised, and whether it carries labels, tells us which algorithms can be used.

Anatomy of a Dataset

A dataset is a table. Each row is an instance (also called an example, sample or record), and each column is an attribute. The columns used as input are the features (or independent variables) and form the feature vector x. The column to be predicted is the label or target (the dependent variable) y. A dataset with m instances and n features is stored as an m × n matrix X together with a vector y of m labels.

Labelled Dataset

In a labelled dataset every instance has a target value. Labels may be numeric (a house price) or categorical (spam or not spam). Labels usually come from human annotators, from past outcomes such as whether a loan was repaid, or from measurement. Getting good labels is often the most expensive step of a project, and wrong labels (label noise) directly reduce model quality.

Unlabelled Dataset

In an unlabelled dataset only the features are present. Such data is easy to collect in large amounts, for example web pages or photographs, but it can only be used for unsupervised learning, or with a small labelled sample for semi-supervised learning.

Types of Features

Features may be numerical (age, income), categorical (city, colour) or ordinal (grade A, B, C, where order matters). Most algorithms need numbers, so categories are converted by encoding, and numerical features are often scaled so that no single feature dominates.

Definition: Feature and label. A feature is an input attribute used to describe an instance; the label (target) is the output value that a supervised model must predict.

Table 1.3: A small labelled dataset

Student Hours Attendance Passed
S1 2 60 No
S2 5 85 Yes
S3 4 90 Yes
S4 1 40 No
S5 6 95 Yes
S6 3 70 No

Example 1.3: Features, label and shapes

Problem: For the table above, identify the instances, features and label, and give the shape of X and y.

Solution:

  1. There are 6 rows (students), so m = 6 instances.
  2. The input columns are Hours and Attendance, so n = 2 features. The student name is only an identifier.
  3. The column Passed is the label.
  4. So X is a 6 × 2 matrix and y has 6 entries. Removing the Passed column gives an unlabelled dataset of 6 rows and 2 columns.

Result: X has shape (6, 2), y has shape (6,), and the label Passed is categorical.

import pandas as pd
df = pd.DataFrame({
    "Hours": [2, 5, 4, 1, 6, 3],
    "Attendance": [60, 85, 90, 40, 95, 70],
    "Passed": ["No", "Yes", "Yes", "No", "Yes", "No"]})
X = df[["Hours", "Attendance"]]
y = df["Passed"]
print("X shape:", X.shape, " y shape:", y.shape)
print("Labels:", sorted(y.unique()))
print("Unlabelled copy columns:", list(X.columns))

Output

X shape: (6, 2)  y shape: (6,)
Labels: ['No', 'Yes']
Unlabelled copy columns: ['Hours', 'Attendance']

Common mistakes

  • Including the label column among the features, which leaks the answer.
  • Treating an identifier such as a roll number as a useful feature.
  • Assuming that more unlabelled data can replace labels for a supervised task.
  • Ignoring label noise.

Key takeaways

  • Row = instance; column = attribute; X = features; y = label.
  • Labelled data allows supervised learning; unlabelled data does not.
  • Features may be numerical, categorical or ordinal.
  • Labels are costly, so label quality matters.

Practice questions

  1. What is the shape of X for m instances and n features?
  2. Which type of learning can use an unlabelled dataset?
  3. Give an example of an ordinal feature.

Answers to the practice questions

  1. m × n.
  2. Unsupervised learning (and semi-supervised with a few labels).
  3. Grade A, B, C, where the order matters.

Sources

  • Official BCA syllabus Introduction to Machine Learning, course code 26BCA404DSE21, Unit I