Skip to learning content

DATA SCIENCE PYTHON PLAYGROUND

Machine Learning · Learn / Refresh

← Regression lessons
Several predictors · ML-R04 · 25–40 MIN

Several predictors, conditional comparisons

Interpret one input while holding others fixed.

  1. FollowRead and run the PythonCurrent exercise
  2. ChangeAdapt the Python
  3. TransferCompute and inspect the evidence
  4. ApplyBuild a guided full workflow

Understand the idea

Multiple regression fits several coefficients together. Each coefficient describes a conditional comparison with the other model inputs held constant.

Interpret one input while holding others fixed.RowDistanceWeightA52B54Predicted difference = 2 × fitted weight coefficientChange one input while holding the other fixed.
Interpret one input while holding others fixed.Scroll the diagram horizontally if needed.

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 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[['distance', 'weight']], y_train. Fitted estimator or pipeline for the requested model family. Fitted on X_train[['distance', 'weight']], y_train; reuse without refitting.

Outputs you create

answer
  1. The requested result, with the values, labels and row order described by this task.
MIX60 · first 8 rows
distanceweightserviceweekendduration
15.70526.75035standard061.7704
9.338694.81674express135.1694
17.31345.73931economy059.0766
14.257.69699standard156.5785
2.789376.42024express019.5577
19.53685.62508economy177.0289
15.46175.68023standard056.8109
15.93523.17871express152.08
Your task
  1. Return named distance and weight coefficients from the supplied fitted two-feature line.
answer
Hints

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.

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.