Understand the idea
A useful model can still omit important factors. Weak predictive results do not prove no relationship; fitted explanations do not establish interventions.
What the syntax does
model.coef_[0]- The fitted change in prediction per one-unit increase in distance for this line.
Supplied for this practice
These objects are prepared afresh before your editor runs.
X- Feature dataframe for the declared population, preserving row indices.
X = df[['distance']] y- Target series, aligned with
X.y = df['duration'] model- Already fitted on
X,y. Fitted estimator or pipeline for the requested model family. Fitted onX,y; reuse without refitting.
Outputs you create
slope- Requested result described in the task and deliverables.
training_r2- Requested result described in the task and deliverables.
distance | duration |
|---|---|
| 1 | 5.30501 |
| 1.47826 | 11.2361 |
| 1.95652 | 11.8488 |
| 2.43478 | 14.809 |
| 2.91304 | 10.7589 |
| 3.3913 | 19.4972 |
| 3.86957 | 17.89 |
| 4.34783 | 15.531 |
- Store the fitted
distancecoefficient inslopeand R² on the training rows intraining_r2. - Explain why neither establishes a causal effect.
slopetraining_r2Hints
Think: Read two fitted summaries and distinguish a model coefficient from a causal claim.
Tools: Use model.coef_[0], model.score(X, y). Read the visible syntax meanings before editing.
Approach: Store the fitted distance coefficient in slope and R² on the training rows in training_r2. Explain why neither establishes a causal effect. Keep the supplied row order and inspect the named output after running.
Explained solution
slope = float(model.coef_[0])
training_r2 = float(model.score(X, y))
A coefficient describes the fitted line for this dataset. Training R² describes how that line fits these seen rows. Neither controls confounders or shows what an intervention would do. Report the population and validation evidence separately from causal claims.