Skip to learning content

DATA SCIENCE PYTHON PLAYGROUND

Machine Learning · Learn / Refresh

← Regression lessonsQUESTIONS · MODELS · EVIDENCE
Several predictors · ML-R-R1 · 15–20 MIN

Regression evidence retrieval

Retrieval 1

Exercises within this concept

  1. Retrieval 1Retrieve and applyCurrent exercise
  2. Retrieval 2Retrieve and apply
  3. Retrieval 3Retrieve and apply
Retrieval 1 · MIX60_REVIEW

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.

MIX60_REVIEW · first 8 prepared rows
distanceweightserviceweekendduration
15.41066.72438standard059.8192
9.548344.7947express136.569
17.21055.70745economy059.5671
14.32977.80743standard156.8985
2.880026.18273express019.4598
19.01235.64716economy176.7485
15.59675.59089standard057.2908
15.67493.15065express153.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.

Input schema
ColumnStored type
distancefloat64
weightfloat64
servicestr
weekendint64
durationfloat64
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.

Retrieve earlier concepts before combining them.Candidate ACandidate BFitValidateCostCompare matching evidence; smaller error can cost more.
Schematic · Retrieve earlier concepts before combining them.Scroll the diagram horizontally if needed.
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.

Your task · Retrieval 1

Retrieve without the worked example: Compare two rows with identical distance and a two-unit weight difference. Use the new retrieval population shown here.

answer

Ctrl/⌘+Enter: Run · Tab: indent · Esc then Tab: leave editor

Python loads when you run. Code and results stay in this activity only.

Run your code to inspect its output. Check uses that same run.

What does a two-unit weight difference imply for the fitted prediction when distance stays fixed?

Use your Run output as evidence. This response is optional, not machine-graded or saved.