Toronto Shelter System — Project Overview

Goal

Analyze Toronto's public shelter occupancy data to understand system pressure, seasonal patterns, and the impact of unavailable beds, then visualize results statically and on an interactive map.


Files

shelter_analysis.py

Core analysis script answering three research questions:

  • Q1 — Sector Pressure: Ranks sectors by average occupancy rate and frequency of hitting 100% capacity. Outputs a side-by-side horizontal bar chart (q1_sector_pressure.png).
  • Q2 — Seasonal Trends: Computes monthly occupancy by year and a sector × season heatmap. Outputs q2_temporal_trends.png.
  • Q3 — Unavailable Beds: Compares official vs. effective occupancy rate (after subtracting unavailable beds) and quantifies the extra pressure per sector. Outputs q3_unavailable_capacity.png.

Key derived columns: EFFECTIVE_CAPACITY, EFFECTIVE_OCCUPANCY_RATE, AT_FULL_CAPACITY, SEASON.


heatmap.py

Animated interactive map of shelter occupancy over time.

  • Loads Public_services.csv, geocodes postal codes via pgeocode (with FSA fallback), bins data by ISO week.
  • Renders a Folium map with:
    • Optional choropleth background (FSA-level service counts, requires shapefile lfsa000b16a_e.shp).
    • Per-shelter animated circles: radius scales with capacity; colour encodes occupancy rate (green → blue → orange).
    • A pulse animation fires when occupancy changes >1 pp week-over-week.
    • A timeline slider + play/pause control injected as custom Leaflet JS.
  • Outputs map.html.

onehot_train.py

Predictive model for shelter pressure.

  • Target: PRESSURE_SCORE_GAUSSIAN (logit-transformed).
  • Features: categorical (sector, service type, postal code, etc.) + numeric (capacity, lat/lon, day/month/dow).
  • Pipeline: OneHotEncoder + SimpleImputerHistGradientBoostingRegressor.
  • Time-aware 80/20 train-test split. Reports MAE, RMSE, and naive baseline.

visualization_draft.py

Quick prototype — geocodes a hardcoded list of postal codes and plots CircleMarkers on a Folium map sized by frequency. Outputs map.html.

playground.py

Variant of the prototype using fixed-radius Circles (2-mile radius, low fill opacity for overlap accumulation) instead of markers.


Data

File Description
public_services_dataset.xlsx Daily shelter occupancy records
Public_services.csv / Public_services_pressure.csv CSV versions; pressure variant includes PRESSURE_SCORE_GAUSSIAN
lfsa000b16a_e.shp Statistics Canada FSA boundary shapefile (optional, for choropleth)

Dependencies

pandas, numpy, matplotlib, seaborn, scikit-learn, folium, geopandas, pgeocode, openpyxl

Share this project:

Updates