Objective: Load the diabetes dataset into a pandas DataFrame, examine its structure and summary statistics, and visually identify which features are most strongly related to the target variable. All directly in your browser, no installation required.
Setup
Every code block below runs live in your browser using Pyodide, a real Python interpreter compiled to
WebAssembly. Click Run on any block to execute it and see actual output. Nothing to install,
no notebook required. We'll use the load_diabetes dataset bundled with scikit-learn: 442 patient
records with 10 baseline physiological measurements (age, sex, BMI, blood pressure, and six blood serum
measurements) and a target value representing disease progression one year later.
Task 1: Load the Dataset and Inspect Its Structure
Load the dataset as a ready-made DataFrame (scikit-learn can do this directly with as_frame=True),
then check its shape, column types, and summary statistics with .describe().
import pandas as pd
from sklearn.datasets import load_diabetes
data = load_diabetes(as_frame=True)
df = data.frame # already a DataFrame with a 'target' column
print("Shape:", df.shape)
print()
print("Dtypes:")
print(df.dtypes)
print()
print("Summary statistics:")
print(df.describe())
You should see 442 rows and 11 columns (10 features plus target), all numeric (float64). Notice the feature values are small numbers like 0.05 or -0.02 rather than raw blood pressure readings. scikit-learn ships this dataset already mean-centered and scaled. That's expected, not a bug.
Task 2: Check for Missing Values
Even when you "know" a dataset is clean, checking is a habit worth building, because in real-world data you usually won't be so lucky.
import pandas as pd
from sklearn.datasets import load_diabetes
data = load_diabetes(as_frame=True)
df = data.frame
missing = df.isna().sum()
print("Missing values per column:")
print(missing)
print()
print("Total missing values:", missing.sum())
You should find zero missing values across every column, since scikit-learn's bundled datasets are pre-cleaned. In a real dataset, this is exactly where you'd decide on an imputation strategy before going any further.
Task 3: Plot the Target's Distribution
A histogram of the target reveals its shape at a glance: whether it's symmetric, skewed, multi-modal, and so on, which matters for later modeling decisions.
import pandas as pd
import matplotlib.pyplot as plt
from sklearn.datasets import load_diabetes
data = load_diabetes(as_frame=True)
df = data.frame
plt.hist(df["target"], bins=30, edgecolor="black")
plt.xlabel("Disease progression score")
plt.ylabel("Count")
plt.title("Distribution of target variable")
show_plot()
You should see a right-skewed distribution: most patients cluster at lower progression scores with a long tail toward higher values. Keep that skew in mind. It's a hint that residual checks will matter once you start modeling this target in later labs.
Task 4: Correlation Matrix, Which Features Track the Target?
Compute the full correlation matrix with .corr(), then pull out just the column that tells you how
each feature relates to the target, sorted from strongest to weakest relationship.
import pandas as pd
from sklearn.datasets import load_diabetes
data = load_diabetes(as_frame=True)
df = data.frame
corr = df.corr()
target_corr = corr["target"].drop("target").sort_values(key=abs, ascending=False)
print("Correlation of each feature with the target (sorted by strength):")
print(target_corr)
print()
print("Top 3 most correlated features:")
print(target_corr.head(3))
You should find that bmi and one or two of the blood serum measurements (commonly labeled
s5 or similar) show the strongest correlation with the target, typically in the 0.4-0.6 range,
while features like sex correlate much more weakly.
This lines up with clinical intuition: body mass index and certain blood markers are well-established risk factors for diabetes progression, while a single demographic feature alone tends to be a much noisier signal once you're already looking at a clinical population.
There's no single "correct" answer here. The goal is practicing the workflow of reading correlation numbers and connecting them back to a real-world story, a skill you'll lean on again in every lab that follows.