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.
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 librariesimport seaborn as sns# Load the datasetpenguins = sns.load_dataset("penguins")# Show the first few rowspenguins.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 descriptions
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 pdurl ="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 valuesnhs_data = nhs_data.dropna()# print first rows nhs_data.head()