Goal
Given housing data, you will:
- Explore price drivers
- Prepare features (missing values, encoding)
- Build a baseline regression pipeline
Analysis pipeline
flowchart LR A["Raw housing data"] --> B["Explore
(price distribution)"] B --> C["Preprocess
(impute, encode, scale)"] C --> D["Train
(baseline regressor)"] D --> E["Evaluate
(MAE / RMSE)"]
Step 1: Load
import pandas as pd
df = pd.read_csv("data/housing.csv")
print(df.shape)
print(df.head())Step 2: EDA: price distribution
import seaborn as sns
import matplotlib.pyplot as plt
plt.figure(figsize=(7, 4))
sns.histplot(df["price"], bins=30, kde=True)
plt.title("House price distribution")
plt.tight_layout()
plt.show()Visualize it
Step 3: Baseline preprocessing
- Identify numeric/categorical
- Impute missing values
- One-hot encode
- Scale numeric (optional)
Use the Phase 4 pipeline approach.
Step 4: Train baseline model
# Use scikit-learn Pipeline + ColumnTransformer
# Choose a baseline model like LinearRegression or RandomForestRegressor
# Evaluate using MAE/RMSE on a held-out test setDeliverable
- Key drivers (most correlated features)
- Data quality issues
- Baseline model performance
Check your understanding
Why do many regression pipelines model log(price) instead of price?
A few very expensive homes stretch the tail, and log compresses that skew.
Show answer
A — Prices are right-skewed with a long tail of expensive homes — A few very expensive homes stretch the tail, and log compresses that skew.
Which metrics evaluate the baseline regression model?
These are regression error metrics, computed on data the model has not seen.
Show answer
A — MAE and RMSE on a held-out test set — These are regression error metrics, computed on data the model has not seen.
Which preprocessing steps does the lesson list for the baseline?
It reuses the Phase 4 pipeline approach with ColumnTransformer and Pipeline.
Show answer
A — Impute missing values, one-hot encode categories and optionally scale numerics — It reuses the Phase 4 pipeline approach with ColumnTransformer and Pipeline.
Why check frame.info() before anything else?
The project stresses checking dtypes and missingness first.
Show answer
A — Dtypes and missing values can quietly break later steps — The project stresses checking dtypes and missingness first.
🧪 Try It Yourself
Exercise 1 – Check missing values
Tab indents. Press Escape, then Tab, to leave the editor. Control plus Enter runs the code; Control plus Shift plus Enter submits it.
Press Run to see what your code prints.Exercise 2 – Correlation with price
Tab indents. Press Escape, then Tab, to leave the editor. Control plus Enter runs the code; Control plus Shift plus Enter submits it.
Press Run to see what your code prints.Exercise 3 – One-hot encode a categorical column
Tab indents. Press Escape, then Tab, to leave the editor. Control plus Enter runs the code; Control plus Shift plus Enter submits it.
Press Run to see what your code prints.