Chapter 4 fit a line to one predictor. Real outcomes depend on many factors. Multiple regression extends the idea to several predictors, and logistic regression handles yes/no outcomes — the two workhorses of practical modelling and the bridge to machine learning.
Multiple regression
Multiple regression predicts a numeric outcome from several inputs at once, estimating the effect of each while holding the others constant:
# package = b0 + b1·experience + b2·projects + b3·skills + errorimport statsmodels.formula.api as smfmodel = smf.ols("package ~ experience + projects + skills", data=df).fit()model.summary() # coefficients, p-values, R²
Interpreting coefficients
- Each coefficient is the effect of that predictor holding the others constant (+1 year experience → +₹X, all else equal).
- Its p-value says whether that effect is statistically distinguishable from zero.
- R² is the share of the outcome's variation the model explains.
Logistic regression
When the outcome is categorical (placed / not placed), linear regression is wrong — you can't predict a 0/1 with a straight line. Logistic regression predicts a probability instead, and is the classic classification model:
from sklearn.linear_model import LogisticRegressionmodel = LogisticRegression().fit(X, y) # y is 0/1model.predict_proba(X_new) # probability of the positive class
Overfitting & assumptions
Practice
Fit a multiple regression of package on experience, projects and skills; interpret one coefficient "holding others constant" and read the R². Then fit a logistic regression predicting placement (0/1) and interpret a predicted probability.
Key takeaways
- 01Multiple regression predicts a numeric outcome from several predictors at once.
- 02Each coefficient is that predictor's effect holding the others constant; R² is variation explained.
- 03Logistic regression predicts a probability for categorical (yes/no) outcomes — a classifier.
- 04More predictors always raise training R² — beware overfitting; validate on held-out data.
- 05Regression assumes linearity, independent errors and no severe multicollinearity.
