How to Load the Diabetes Dataset in Python with scikit-learn
The diabetes dataset is scikit-learn's small built-in dataset for regression, predicting a number rather than a class. Each of its 442 rows is a patient with 10 measurements, and the target measures how the disease progressed one year later. This guide loads it with load_diabetes, with real output from scikit-learn 1.9.1.
Syntax
from sklearn.datasets import load_diabetes
<dataset> = load_diabetes(as_frame=True)
X, y = load_diabetes(return_X_y=True, as_frame=True, scaled=<True or False>)
| Part | What it means |
|---|---|
as_frame=True | Returns pandas objects instead of NumPy arrays |
scaled= | True by default: the features come already centered and scaled. False gives the raw values |
return_X_y=True | Returns just the features and the target |
The scikit-learn reference: "If True, the feature variables are mean centered and scaled by the standard deviation times the square root of n_samples. If False, raw data is returned for the feature variables."
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
from sklearn.datasets import load_diabetes
diabetes = load_diabetes(as_frame=True)
print(diabetes.frame.shape)
print(diabetes.feature_names)
print(diabetes.frame[["age", "bmi", "target"]].head(3))

Step 2: Run It
uv run python load_diabetes_demo.py
(442, 11)
['age', 'sex', 'bmi', 'bp', 's1', 's2', 's3', 's4', 's5', 's6']
age bmi target
0 0.038076 0.061696 151.0
1 -0.001882 -0.051474 75.0
2 0.085299 0.044451 141.0

The ages aren't years: by default the features come centered and scaled. The target is in its own units; it ranged from 25.0 to 346.0.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
Reading age as years | The default values are scaled, such as 0.038076 | Load with scaled=False for the raw values: the first three ages were then 59.0, 48.0 and 72.0 |
| Treating it as a classification dataset | The target is a number to predict, not a class | Use regression models, such as linear regression |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| Every feature's mean is about 0 | That's the default scaling: the mean of age came out as -0.0 and its sum of squares as 1.0 | Pass scaled=False if you want to scale it yourself |
FAQ
What do s1 to s6 mean?
They're blood measurements. The toy dataset description lists them as total serum cholesterol, LDL, HDL, total cholesterol / HDL, "possibly log of serum triglycerides level" and blood sugar level.
How do I get X and y?
X, y = load_diabetes(return_X_y=True, as_frame=True) gives the 10 features as a DataFrame and the target as a Series.
Conclusion
load_diabetes(as_frame=True) loaded 442 patients with 10 scaled features and a number to predict. Pass scaled=False when you need the original values.
Additional Resources
- load_diabetes — the function, including
scaled. - Toy datasets — what each column measures.
