Skip to learning content

DATA SCIENCE PYTHON PLAYGROUND

Machine Learning · Learn / Refresh

← Regression lessons
Curves and trees · ML-R11 · 12–18 MIN

What fitted explanations cannot establish

Match claim strength to the evidence.

  1. FollowRead and run the PythonCurrent exercise
  2. ChangeCompute and inspect the evidence
  3. TransferCompute and inspect the evidence

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.

Match claim strength to the evidence.Observed: predictive error under this evaluationQualify: population, model, inputs and uncertaintyPrediction evidence alone does not identify causal effects.
Match claim strength to the evidence.Scroll the diagram horizontally if needed.

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 on X, y; reuse without refitting.

Outputs you create

slope
  1. Requested result described in the task and deliverables.
training_r2
  1. Requested result described in the task and deliverables.
LINE24 · first 8 rows
distanceduration
15.30501
1.4782611.2361
1.9565211.8488
2.4347814.809
2.9130410.7589
3.391319.4972
3.8695717.89
4.3478315.531
Your task
  1. Store the fitted distance coefficient in slope and R² on the training rows in training_r2.
  2. Explain why neither establishes a causal effect.
slopetraining_r2
Hints

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.

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.