Datasets

Iris Dataset

The Iris dataset, introduced by British statistician and biologist Ronald A. Fisher in 1936, is one of the most iconic datasets in the history of machine learning and statistics. It contains measurements of 150 iris flowers, evenly split across three species — Iris setosa, Iris versicolor, and Iris virginica — with each flower described by four features: sepal length, sepal width, petal length, and petal width, all measured in centimetres. Its appeal lies in its simplicity and structure: one class (setosa) is linearly separable from the other two, while the remaining pair overlaps slightly, making it an ideal sandbox for exploring both simple and more nuanced classification algorithms.

We can load the dataset directly from the Python pandas library.

import pandas as pd
from sklearn.datasets import load_iris
import matplotlib.pyplot as plt

iris = load_iris(as_frame=True)
df = iris.frame
df["species"] = df["target"].map({0: "setosa", 1: "versicolor", 2: "virginica"})
df = df.drop(columns=["target"])

df.head(6)
sepal length (cm) sepal width (cm) petal length (cm) petal width (cm) species
0 5.1 3.5 1.4 0.2 setosa
1 4.9 3.0 1.4 0.2 setosa
2 4.7 3.2 1.3 0.2 setosa
3 4.6 3.1 1.5 0.2 setosa
4 5.0 3.6 1.4 0.2 setosa
5 5.4 3.9 1.7 0.4 setosa

The first few rows of the Iris dataset.

Palmer Penguins Dataset

The Palmer Penguins dataset was collected by Dr. Kristen Gorman at Palmer Station, Antarctica.

Gorman KB, Williams TD, Fraser WR (2014) Ecological Sexual Dimorphism and Environmental Variability within a Community of Antarctic Penguins (Genus Pygoscelis). PLoS ONE 9(3): e90081. doi:10.1371/journal.pone.0090081

It contains measurements for 344 penguins belonging to three species:

  • Adélie (Pygoscelis adeliae)
  • Chinstrap (Pygoscelis antarcticus)
  • Gentoo (Pygoscelis papua)

Artwork by @allison_horst

The features available are:

Feature Type Description
bill_length_mm Numeric Length of the bill in millimetres
bill_depth_mm Numeric Depth (height) of the bill in millimetres
flipper_length_mm Numeric Flipper length in millimetres
body_mass_g Numeric Body mass in grams
island Categorical Biscoe, Dream, or Torgersen
sex Categorical Male or Female


We can load the dataset directly from the Python seaborn library.

# Load libraries
import seaborn as sns

# Load the dataset
penguins = sns.load_dataset("penguins")

# Show the first few rows
penguins.head()
species island bill_length_mm bill_depth_mm flipper_length_mm body_mass_g sex
0 Adelie Torgersen 39.1 18.7 181.0 3750.0 Male
1 Adelie Torgersen 39.5 17.4 186.0 3800.0 Female
2 Adelie Torgersen 40.3 18.0 195.0 3250.0 Female
3 Adelie Torgersen NaN NaN NaN NaN NaN
4 Adelie Torgersen 36.7 19.3 193.0 3450.0 Female

Using your own dataset

With pandas, you can easily load your own datasets from various formats, such as CSV, Excel, or SQL databases.

For example, we can load the CSV file nhs_readmission.csv. This dataset is entirely synthetic, generated purely as a teaching example.

  • Simulated distributions based on typical NHS inpatient population parameters (e.g. age ~Normal(62, 16), length of stay ~Exponential(4.5), HbA1c ~Normal(60, 18))
  • Clinically plausible missingness patterns (HbA1c missing in ~16% of patients, eGFR in ~9%)
  • A logistic outcome model where readmission probability depends on age, Charlson index, length of stay, prior ED attendances, eGFR, and IMD decile
Column Description
patient_id Anonymous patient identifier
age Age in years at admission
sex M / F
imd_decile Index of Multiple Deprivation (1 = most deprived, 10 = least)
primary_diagnosis ICD-10 code for primary diagnosis
charlson_index Charlson Comorbidity Index (0–37)
hba1c Most recent HbA1c (mmol/mol) — missing if not tested
egfr Most recent eGFR (mL/min/1.73m²) — missing if not tested
bmi Body Mass Index (kg/m²)
los_days Length of stay in days
ed_prior_year ED attendances in previous 12 months
discharge_ward Ward the patient was discharged from
readmitted_30d Readmitted within 30 days: Yes / No
import pandas as pd

url = "https://raw.githubusercontent.com/Bristol-Training/nhs-data-science/refs/heads/main/data/nhs_readmission.csv"

nhs_data = pd.read_csv(
    url,
    skiprows=3, # skip header rows with metadata
    index_col="patient_id", # this column is an identifier each row
    na_values=[".", "N/A", "NULL", "UNKNOWN"],  # recode common placeholders as NaN
)

print("Missing values per column:")
print(nhs_data.isnull().sum())
Missing values per column:
age                    0
sex                    0
imd_decile             0
primary_diagnosis      0
charlson_index         0
hba1c                811
egfr                 445
bmi                   65
los_days               0
ed_prior_year         25
discharge_ward         0
readmitted_30d         0
dtype: int64
# delete rows with missing values
nhs_data = nhs_data.dropna()

# print first rows 
nhs_data.head()
age sex imd_decile primary_diagnosis charlson_index hba1c egfr bmi los_days ed_prior_year discharge_ward readmitted_30d
patient_id
1001 69 M 8 E11 2 67.6 29.4 36.4 5 1.0 Endocrine No
1002 59 M 2 I10 4 67.5 42.8 37.8 4 2.0 General Medicine No
1003 72 M 2 I63 1 44.1 61.7 26.2 3 1.0 Gastro No
1004 86 M 10 J18 1 55.5 62.9 34.0 2 1.0 General Medicine No
1005 58 M 10 C34 2 59.8 120.0 18.5 6 0.0 Respiratory No

Other datasets

scikit-learn example datasets https://scikit-learn.org/stable/datasets.html

Kaggle open datasets https://www.kaggle.com/datasets

Hugging face datasets https://huggingface.co/datasets