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 withX_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 onX_train,y_train; reuse without refitting.
Outputs you create
answer- The requested result, with the values, labels and row order described by this task.
case_id | backlog_at_open | device_age_years | completion_hours | invoice_hours |
|---|---|---|---|---|
| 4100 | 7 | 2.88157 | 9.42823 | 9.67823 |
| 4101 | 11 | 8.87485 | 17.2581 | 17.5081 |
| 4102 | 3 | 2.2896 | 7.74669 | 7.99669 |
| 4103 | 13 | 1.17218 | 14.7785 | 15.0285 |
| 4104 | 3 | 4.75178 | 5.76434 | 6.01434 |
| 4105 | 6 | 3.25684 | 8.09476 | 8.34476 |
| 4106 | 2 | 4.57092 | 4.09819 | 4.34819 |
| 4107 | 11 | 1.42743 | 11.8684 | 12.1184 |
Your task
- The repair line has
backlog_at_openanddevice_age_yearsin that order. - Compare an intake with backlog 3/age 5 to one with backlog 5/age 4.
- Return
answeras aSeriesindexed backlog_contribution, age_contribution, total_change. - Each contribution must describe the conditional fitted change; verify their sum against the two-row prediction difference.
answerHints
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.