Skip to main content

How to Load the Linnerud Dataset in Python with scikit-learn

· 3 min read
Jagdish Kumawat
Founder @ Dewiride

Most datasets have one thing to predict. The Linnerud dataset has three: from 20 people's exercise counts, predict their weight, waist and pulse together. That makes it the small built-in dataset for multi-output regression. This guide loads it with load_linnerud, with real output from scikit-learn 1.9.1.

Syntax​

Syntax
from sklearn.datasets import load_linnerud

<dataset> = load_linnerud(as_frame=True)
X, y = load_linnerud(return_X_y=True, as_frame=True)
PartWhat it means
<dataset>.dataThe three exercises: Chins, Situps and Jumps
<dataset>.targetThe three values to predict: Weight, Waist and Pulse
<dataset>.frameBoth tables side by side in one DataFrame

The scikit-learn reference: "Load and return the physical exercise Linnerud dataset. This dataset is suitable for multi-output regression tasks."

Prerequisites​

  • scikit-learn and pandas in your project, for example with uv add scikit-learn pandas. This guide uses scikit-learn 1.9.1 and pandas 3.1.1 on Python 3.15.2.

Step 1: Write the Script​

load_linnerud_demo.py
from sklearn.datasets import load_linnerud

linnerud = load_linnerud(as_frame=True)

print(linnerud.data.shape, linnerud.target.shape)
print(linnerud.feature_names)
print(linnerud.target_names)
print(linnerud.frame.head(3))

The load_linnerud_demo.py script in a macOS-style code window: load_linnerud(as_frame=True), then print of the data and target shapes, the feature and target names, and the first three rows of the frame.

Step 2: Run It​

Terminal
uv run python load_linnerud_demo.py
Output
(20, 3) (20, 3)
['Chins', 'Situps', 'Jumps']
['Weight', 'Waist', 'Pulse']
Chins Situps Jumps Weight Waist Pulse
0 5.0 162.0 60.0 191.0 36.0 50.0
1 2.0 110.0 60.0 189.0 37.0 52.0
2 12.0 101.0 101.0 193.0 38.0 58.0

The script's output in a terminal: data and target shapes of (20, 3), the exercise names Chins, Situps and Jumps, the target names Weight, Waist and Pulse, and the first three rows.

Twenty people, three exercises in, three measurements out.

Common Mistakes​

MistakeWhat happensDo this instead
Expecting y to be one columnIt's a DataFrame with three columns: Weight, Waist and PulseUse a model that predicts several outputs, or pick one column, such as y["Weight"]
Judging a model on 20 rowsA test set from 20 rows has only a handful of peopleUse it to learn the API, not to compare models

Troubleshooting​

SymptomLikely causeFix
linnerud.frame is NoneLoaded without as_frame=True: load_linnerud().frame printed NoneLoad it again with as_frame=True

FAQ​

Is y a Series like in other datasets?​

No: load_linnerud(return_X_y=True, as_frame=True) gave a DataFrame for y, with the columns Weight, Waist and Pulse.

Which models can predict all three at once?​

Several scikit-learn regressors accept a target with several columns. LinearRegression, fitted on X and the three-column y, predicted three numbers per person: [176.2 35.1 57.1] for the first.

Conclusion​

load_linnerud(as_frame=True) loaded 20 people with three exercises as the data and three body measurements as the target: a small dataset for predicting several numbers at once.

Additional Resources​