Understand the idea
Rows are observations. X is a two-dimensional feature table; y is the target for the same observations. Select columns by meaning, not simply by numeric dtype.
Python skill: Selects a list of feature columns and keeps a two-dimensional dataframe.
Meet the syntax
X = df[['distance']]
y = df['duration']df[['distance']]- Selects a list of feature columns and keeps a two-dimensional dataframe.
df['duration']- Selects one aligned target column as a series.
X- Names the feature table.
y- Names the target values aligned to X.
Follow the code
Use the numbered comments to connect each Python block to the workflow above.
X=df[['distance']]
y=df['duration']
This practice: Read and run the Python. Next: Change · Features and target.
Given data · LINE12
12 observations. Deterministic teaching observations; values illustrate the concept rather than a real population claim. The dataframe df is supplied afresh for each Run.
| distance | duration |
|---|---|
| 1 | 8 |
| 2 | 11 |
| 2 | 13 |
| 3 | 14 |
| 4 | 20 |
| 5 | 22 |
| 5 | 24 |
| 6 | 25 |
| 7 | 31 |
| 8 | 33 |
| 9 | 35 |
| 10 | 41 |
Column meanings and units
Column names describe the supplied features and target. Keep the stated units and row identities when making comparisons.
Synthetic data are deliberately small and reproducible. Their patterns illustrate an idea; they are not evidence about a real population.
| Column | Stored type |
|---|---|
| distance | int64 |
| duration | int64 |
Your task · Follow
Create X with distance and y with duration.
Hint 1 — Think
The estimator needs inputs and outcomes in separate objects without changing their row order.
Hint 2 — Tools
Dataframe column selection; X as a table and y as a series.
Hint 3 — Approach
Select the distance column as a feature table and the duration column as its aligned target.
Explained solution
X=df[['distance']]
y=df['duration']
Keeping X two-dimensional preserves the estimator interface even with one feature; the separate y supplies the outcomes to learn.
Helpful prior knowledge: What question are we answering? These links are guidance, not locks.
Sources and API context
Examples run with this Playground’s scikit-learn 1.4.2 / Pyodide 0.26.4 runtime.