Retrieve without the worked example: Compare two rows with identical distance and a two-unit weight difference.
Use the new retrieval population shown here.
Retrieve earlier concepts before combining them.
This practice: Retrieve earlier concepts before combining them. Next: Retrieval 2 · Regression evidence retrieval.
Given data · MIX60_REVIEW
60 observations. Deterministic teaching observations; values illustrate the concept rather than a real population claim. The dataframe df is supplied afresh for each Run.
| distance | weight | service | weekend | duration |
|---|---|---|---|---|
| 15.4106 | 6.72438 | standard | 0 | 59.8192 |
| 9.54834 | 4.7947 | express | 1 | 36.569 |
| 17.2105 | 5.70745 | economy | 0 | 59.5671 |
| 14.3297 | 7.80743 | standard | 1 | 56.8985 |
| 2.88002 | 6.18273 | express | 0 | 19.4598 |
| 19.0123 | 5.64716 | economy | 1 | 76.7485 |
| 15.5967 | 5.59089 | standard | 0 | 57.2908 |
| 15.6749 | 3.15065 | express | 1 | 53.9559 |
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 | float64 |
| weight | float64 |
| service | str |
| weekend | int64 |
| duration | float64 |
Supplied setup · available if you need to inspect it
This code runs before your editor on every Run. These are the objects your exercise uses.
from sklearn.model_selection import train_test_split
X = df[['distance','weight','service','weekend']]
y = df['duration']
X_train,X_test,y_train,y_test=train_test_split(X,y,test_size=.2,random_state=42)
from sklearn.linear_model import LinearRegression
model=LinearRegression().fit(X_train[['distance','weight']],y_train)
Supporting concepts: Read residual patterns and limits → · Read coefficients after encoding →
Remember the idea
Use the inputs and evidence to recover the method. Hints and explained solutions remain collapsed; exact phrasing is not graded.
Hint 1 — Think
Recall what must stay fixed to interpret one predictor’s contribution.
Hint 2 — Tools
Matched feature rows, predict and a difference.
Hint 3 — Approach
Create the requested matched pair and subtract its predictions in row order.
Explained solution
rows=pd.DataFrame({'distance':[5,5],'weight':[2,4]})
answer=float(np.diff(model.predict(rows))[0])
The difference isolates the fitted weight contribution while holding distance unchanged in this retrieval population.
Helpful prior knowledge: Read residual patterns and limits · Read coefficients after encoding 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.