Skip to learning content

DATA SCIENCE PYTHON PLAYGROUND

Machine Learning · Learn / Refresh

← Regression lessons
Several predictors · ML-R-R1 · 15–20 MIN

Regression evidence retrieval

  1. Retrieval 1Retrieve and applyCurrent exercise
  2. Retrieval 2Retrieve and apply
  3. Retrieval 3Compute and inspect the evidence

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[['backlog_at_open', 'device_age_years']]
y
Target series, aligned with X.
y = df['completion_hours']
X_train / X_test / y_train / y_test
Training feature rows from the declared split. Final-test feature rows from the declared split. Training targets, aligned with X_train. Final-test targets, aligned with X_test.
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
model
Already fitted on X_train, y_train. Fitted estimator or pipeline for the requested model family. Fitted on X_train, y_train; reuse without refitting.

Outputs you create

answer
  1. The requested result, with the values, labels and row order described by this task.
INTAKE48 · first 8 rows
case_idbacklog_at_opendevice_age_yearscompletion_hoursinvoice_hours
410072.881579.428239.67823
4101118.8748517.258117.5081
410232.28967.746697.99669
4103131.1721814.778515.0285
410434.751785.764346.01434
410563.256848.094768.34476
410624.570924.098194.34819
4107111.4274311.868412.1184
Your task
  1. The repair line has backlog_at_open and device_age_years in that order.
  2. Compare an intake with backlog 3/age 5 to one with backlog 5/age 4.
  3. Return answer as a Series indexed backlog_contribution, age_contribution, total_change.
  4. Each contribution must describe the conditional fitted change; verify their sum against the two-row prediction difference.
answer
Hints

Think: Each coefficient contributes its input change times its fitted weight.

Tools: Named coefficient order and a two-row prediction difference.

Approach: Separate backlog and age contributions, then check that they sum to the total fitted change.

Explained solution
rows = pd.DataFrame({'backlog_at_open':[3,5],'device_age_years':[5,4]})
answer = pd.Series([2*model.coef_[0],-model.coef_[1],float(np.diff(model.predict(rows))[0])],index=['backlog_contribution','age_contribution','total_change'])

The two-unit backlog rise and one-year age fall produce opposing conditional contributions. Their sum is the fitted total change; none of these quantities is a causal intervention effect.

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.