Chapter 3 · Section 9 practice

Extension: Pharmacy Profit and Model Comparison

Work from question 1 to 10. Edit your Python box, click Run Code, review the result, then click Submit attempt. Reference answers unlock after all ten attempts are submitted. This records completion, not correctness. Each box runs independently. Progress is saved in this browser.

Submitted: 0 / 10

1. Check the allocation

Warm-up. Print the numbers of training, validation and test cities, and whether all three index sets are disjoint.

Write your answer, then run it.

2. Count candidate subsets

Warm-up. Use combinations to count all nonempty subsets of the six inputs.

Write your answer, then run it.

3. Compare validation scores

Warm-up. Print full-model and selected-model validation adjusted R-squared and course RMSE s in USD.

Write your answer, then run it.

4. Inspect the training p-values

Build your skills. Print the name and p-value of the full model’s largest slope p-value.

Write your answer, then run it.

5. Read the explicit selected list

Build your skills. Print the selected predictor list and its training residual degrees of freedom.

Write your answer, then run it.

6. Rank every candidate

Build your skills. Enumerate all 63 subsets, score validation RMSE s, and print the best predictor list.

Write your answer, then run it.

7. Predict the proposed store

Build your skills. Print the selected training model’s predicted Profit for the supplied Kansas City inputs.

Write your answer, then run it.

8. Calculate test RMSE s

Challenge. Freeze the selected training model and calculate course RMSE s on the 22 test cities.

Write your answer, then run it.

9. Calculate test adjusted R-squared

Challenge. Calculate adjusted R-squared for the selected model’s held-out predictions.

Write your answer, then run it.

10. Compare an input while holding others fixed

Challenge. Print the fitted Profit difference for a one-percentage-point higher age-65+ share under the selected model.

Write your answer, then run it.

Reference answers are locked until all 10 attempts are submitted.