Introduction: Data Comes First
A machine-learning model is a summary of the data it was trained on. It cannot know anything the data does not show, and it will faithfully learn every mistake the data contains: a column recorded in pounds for half the rows and kilograms for the rest, a label that an annotator clicked by accident, a customer who appears three times. "Garbage in, garbage out" is older than machine learning, but it bites harder here, because a model trained on flawed data still produces confident numbers.
This course is about the part of the work that happens before any model is trained: knowing what kind of data you have, how it is stored, where it came from and whether you are allowed to use it, and how good it is. It is wave M1 of the Machine Learning track, together with ML Foundations. The next course, Data Preparation, fixes the problems this course teaches you to find.
The journey of a dataset
The sections of the course follow this path:
| Section | Questions it answers |
|---|---|
| Data Types | Is a column a number, a category, a ranking, a date, text, an image, a sound, a network? What does each look like in code? |
| Dataset Vocabulary | What are samples, features, labels, ground truth, annotations and metadata? |
| Formats and Storage | How are CSV, JSON, XML, SQL tables, Parquet and folders of images read and written, and when is each the right choice? How do you version a dataset? |
| Data Sources | Where does data come from, and what privacy, consent, licensing and retention rules come with it? |
| Exploring Data Quality | How do you inspect a dataset, describe it, and find missing values, duplicates, outliers, bad labels, imbalance and inconsistencies? How do you write all of that up reproducibly? |
The course ends with exercises and a mini project, a Dataset Quality Analyzer that produces a quality report for any table.
A first look at messy data
Here is a tiny table of the kind you will meet in practice: eight patient visits at a clinic, typed in by two people. It is invented for this course, like every dataset you will see here that does not ship with a library.
import pandas as pd
visits = pd.DataFrame({
"patient_id": [101, 102, 103, 103, 104, 105, 106, 107],
"age": [34, 51, None, None, 29, 47, 230, 62],
"weight": [72.5, 88.0, 65.2, 65.2, 154.0, 70.1, 80.3, None],
"smoker": ["no", "yes", "No", "No", "no", "Y", "no", "yes"],
"diagnosis": ["healthy", "flu", "healthy", "healthy", "healthy", "flu", "healthy", "covid"],
})
print(visits)
print()
print("rows:", len(visits))
print("missing values per column:", visits.isna().sum().to_dict())
print("fully duplicated rows:", visits.duplicated().sum())
print("spellings of 'smoker':", sorted(visits["smoker"].unique())) patient_id age weight smoker diagnosis
0 101 34.0 72.5 no healthy
1 102 51.0 88.0 yes flu
2 103 NaN 65.2 No healthy
3 103 NaN 65.2 No healthy
4 104 29.0 154.0 no healthy
5 105 47.0 70.1 Y flu
6 106 230.0 80.3 no healthy
7 107 62.0 NaN yes covid
rows: 8
missing values per column: {'patient_id': 0, 'age': 2, 'weight': 1, 'smoker': 0, 'diagnosis': 0}
fully duplicated rows: 1
spellings of 'smoker': ['No', 'Y', 'no', 'yes']
Even this small table has five kinds of problems, and each one has its own lesson later in the course:
- Missing values: two ages and one weight are empty (Missing-Value Analysis).
- A duplicate: patient 103 was entered twice (Duplicate Detection).
- An impossible value: an age of 230 is a typo, probably 23 (Outlier Detection).
- A unit mix-up: a weight of 154.0 for a 29-year-old is plausible in pounds, about 70 kg (Data Consistency).
- Inconsistent categories: "no", "No", "Y" and "yes" mean two things written four ways.
The diagnosis column has a sixth issue that is easy to miss: one class, "covid", has a single example. A model cannot learn much from one example (Class Distribution).
Why this matters for the model
A quick experiment shows what happens when a model trains on wrong labels. We take scikit-learn's built-in breast cancer dataset, flip a growing share of the training labels at random, and measure accuracy on a test set whose labels are left correct.
import numpy as np
from sklearn.datasets import load_breast_cancer
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler
X, y = load_breast_cancer(return_X_y=True)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=0, stratify=y)
rng = np.random.default_rng(0)
for share in [0.0, 0.1, 0.2, 0.3, 0.4]:
noisy = y_train.copy()
flip = rng.choice(len(noisy), size=int(share * len(noisy)), replace=False)
noisy[flip] = 1 - noisy[flip]
model = make_pipeline(StandardScaler(), LogisticRegression(max_iter=1000))
model.fit(X_train, noisy)
print(f"{share:.0%} of training labels flipped -> test accuracy {model.score(X_test, y_test):.3f}")0% of training labels flipped -> test accuracy 0.959
10% of training labels flipped -> test accuracy 0.936
20% of training labels flipped -> test accuracy 0.918
30% of training labels flipped -> test accuracy 0.924
40% of training labels flipped -> test accuracy 0.830
The test set has 171 samples (30% of 569, split with random_state=0), and its labels are never touched. The model is the same in every row; only the quality of its training data changes. Accuracy drops from 0.959 with clean labels to 0.830 when 40% are flipped. The drop is not perfectly smooth (30% happens to score slightly better than 20%), because which labels get flipped matters as much as how many: a flipped label far from the decision boundary does little harm, one near it does a lot. Real label errors are often not random at all: annotators tend to make mistakes on the hard, borderline cases, which is exactly where they hurt most.
How the lessons work
Every example is Python that runs in your browser, with pandas, NumPy, Matplotlib, scikit-learn, PyArrow and the standard library (csv, json, sqlite3, xml). Nothing is downloaded: the data is either built in code, as above, or comes with a library (load_iris, load_wine, load_breast_cancer, load_digits, and sample images from skimage.data). Anything random uses a fixed seed, so the output under each example is exactly what you get when you run it. Edit the code and run it again; that is the fastest way to learn.
You should be comfortable with pandas DataFrames and with the ideas in ML Foundations. When a lesson uses a statistical idea, it links to the Statistics course for the details.
Test yourself
A model is trained on data where 30% of the labels are wrong. What usually happens?
- Nothing, models ignore wrong labels automatically
- The model learns from the wrong labels too and gets worse on correctly labelled test data
- Training fails with an error
- The model becomes more accurate because of the extra variety
In the clinic table, a weight of 154.0 for one patient is most likely a…
- Missing value
- Duplicate
- Unit mix-up (pounds instead of kilograms)
- Label error
Which of these is checked in this course, before data preparation starts?
- Choosing the learning rate
- Finding duplicates, missing values and inconsistent categories
- Deploying the model to a server
- Tuning the number of trees in a forest