visitsA day of the week is a category, not a quantity. Drop one into a regression as a raw number (Monday = 1, Sunday = 7) and the model fits one straight slope through seven days that do not line up that way. The fix is to encode the day as a set of yes/no dummies and drop one of them as a base case. Below is a live OLS predicting daily visits to a Utah ski resort across two seasons. Flip between the two encodings and watch the same data go from one meaningless slope to a clean per-day reading. The goal is to feel the difference, not just be told it.
day_of_week and fit OLS for visitsPick an encoding. The dataset and the target never change — only how the day of the week enters the regression.
| term | value | what it reads as |
|---|
These are the actual average visits per day across the two seasons. They are what every encoding is trying to reproduce. With a base case, the intercept is one of these averages and each coefficient is the gap between two of them.
| day | day_number | avg visits | days observed |
|---|
cost ~ Volume + quarter dummies, where Volume is continuous and the quarter dummies are categorical.
The categorical predictors always follow the same rules:
pandas.get_dummies only drops a level when you pass drop_first=True; it does not read anything from the column
name, it just drops the first category. statsmodels' C(day_of_week) goes one step further: it builds the dummies and drops a
reference level automatically. In Excel there is no helper, so you build the yes/no columns by hand and leave one out on purpose.
The mechanic differs; the rule does not.
import pandas as pd
import statsmodels.formula.api as smf
# 1. pandas: you opt in to dropping the base with drop_first=True
dummies = pd.get_dummies(df["day_of_week"], drop_first=True)
# -> 6 columns; the first day (alphabetical) becomes the base case
# 2. statsmodels: C() builds the dummies and drops a reference level for you
model = smf.ols("visits ~ C(day_of_week)", data=df).fit()
print(model.params) # intercept = base-day mean; each coef = that day vs base