Python Central HubSign in

Data Analytics with Python / Phase 10: Data Analytics Projects

Housing Price Prediction (Regression)

Prepare a housing dataset, explore feature relationships, and build a regression-ready pipeline.

Goal

Given housing data, you will:

  • Explore price drivers
  • Prepare features (missing values, encoding)
  • Build a baseline regression pipeline

Analysis pipeline

diagram Housing regression pipeline mermaid
From raw listings to a baseline price-prediction model.

Step 1: Load

Python
import pandas as pd
 
df = pd.read_csv("data/housing.csv")
print(df.shape)
print(df.head())

Step 2: EDA: price distribution

Python
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

sketch House price distribution (right-skewed) p5.js
Most homes cluster on the left; a long tail of expensive homes stretches right.

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

Python
# Use scikit-learn Pipeline + ColumnTransformer
# Choose a baseline model like LinearRegression or RandomForestRegressor
# Evaluate using MAE/RMSE on a held-out test set

Deliverable

  • Key drivers (most correlated features)
  • Data quality issues
  • Baseline model performance

Check your understanding

quizCheck yourself
  1. Why do many regression pipelines model log(price) instead of price?

    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.

  2. Which metrics evaluate the baseline regression model?

    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.

  3. Which preprocessing steps does the lesson list for the baseline?

    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.

  4. Why check frame.info() before anything else?

    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

exerciseYour turn

Tab indents. Press Escape, then Tab, to leave the editor. Control plus Enter runs the code; Control plus Shift plus Enter submits it.

Output
Press Run to see what your code prints.

Exercise 2 – Correlation with price

exerciseYour turn

Tab indents. Press Escape, then Tab, to leave the editor. Control plus Enter runs the code; Control plus Shift plus Enter submits it.

Output
Press Run to see what your code prints.

Exercise 3 – One-hot encode a categorical column

exerciseYour turn

Tab indents. Press Escape, then Tab, to leave the editor. Control plus Enter runs the code; Control plus Shift plus Enter submits it.

Output
Press Run to see what your code prints.

Was this page helpful?

Let us know how we did