Python for Introductory Statistics: Lab WorkbookXYZ Homework Edition

⇩ Download ▾

14.5 Regression

Multiple Linear Regression

Watch demo video

Lab 14.5.1

The dataset in the website (URL below) includes 20 columns about home sale, including price, number of bedrooms and bathrooms, areas etc. The data includes 21,613 entries.

  1. Write a Python code to find the least-squares prediction equation, y=β0+β1x1+β2x2+β3x3+ϵy=\beta_0+\beta_1x_1+\beta_2x_2+\beta_3x_3 +\epsilon for these data where, yy is price, x1x_1 is bedrooms, x2x_2 sqft_basement and x3x_3 is sqft_living.
  2. Use the overall F test to determine whether the model contributes significant information to the prediction of yy with 1% level of significance.
  3. What is the value of R-squared. That is, the coefficient of determination.
  4. Does the sqft_living, x3x_3, contribute significant information for the prediction of the price, yy, given that x1x_1 and x2x_2 are already in the model? (use α=0.05\alpha = 0.05)

kc_house_data.csv

view answer

Logistic Regression

Lab 14.5.2

The data set below (URL) contains the occurrence of coronary heart disease, chd, tobacco, obesity, age, alcohol, etc. For chd, 0 means patient has no chd and 1 means patient has chd.

  1. Write a Python code to read the data set and display the first five rows.
  2. Write a Python code to fit a logistic regression model where the dependent variable is chd and the predictor variables are ldl, sbs and age. Use 5% level of significance.

heart.csv

view answer

Adapted from Python for Introductory Statistics: Student's Lab Workbook, by Simon Aman (Truman College, City Colleges of Chicago), licensed under CC BY 4.0. Changes were made: reformatted as an accessible XYZ web edition with live in-browser code cells. License: CC-BY-4.0.

These eBooks are a prerelease and are not yet certified conformant with WCAG 2.1 AA or ADA Title II. Every page is built against an automated accessibility gate, and the published editions will meet ADA Title II requirements when they release in late September 2026. If something is unusable, please tell us.