Understand the idea
Multiple regression fits several coefficients together. Each coefficient describes a conditional comparison with the other model inputs held constant.
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', 'weight', 'service', 'weekend']] y- Target series, aligned with
X.y = df['duration'] 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[['distance', 'weight']],y_train. Fitted estimator or pipeline for the requested model family. Fitted onX_train[['distance', 'weight']],y_train; reuse without refitting.
Outputs you create
answer- The requested result, with the values, labels and row order described by this task.
distance | weight | service | weekend | duration |
|---|---|---|---|---|
| 15.7052 | 6.75035 | standard | 0 | 61.7704 |
| 9.33869 | 4.81674 | express | 1 | 35.1694 |
| 17.3134 | 5.73931 | economy | 0 | 59.0766 |
| 14.25 | 7.69699 | standard | 1 | 56.5785 |
| 2.78937 | 6.42024 | express | 0 | 19.5577 |
| 19.5368 | 5.62508 | economy | 1 | 77.0289 |
| 15.4617 | 5.68023 | standard | 0 | 56.8109 |
| 15.9352 | 3.17871 | express | 1 | 52.08 |
- Return named
distanceandweightcoefficients from the supplied fitted two-feature line.
answerHints
Think: Coefficient labels must follow the order used when fitting the supplied two-feature model.
Tools: model.coef_ and pd.Series with an index.
Approach: Pair the fitted coefficients with distance and weight in training-column order.
Explained solution
answer=pd.Series(model.coef_,index=['distance','weight'])
Named coefficients preserve which conditional association each learned value describes.