Predicts PG&E Public Safety Power Shutoff (PSPS) risk for an address over the next 14 days, using a classifier trained on PG&E's own historical PSPS post-event reports and Open-Meteo weather data.
Scope: this model only understands PG&E's Northern/Central California service territory. It was trained on 23 PG&E PSPS post-event reports (2021–2026) filed with the CPUC, covering 32 counties. Addresses outside PG&E's footprint, or inside it but in a county with no incident history in the training data, are called out explicitly rather than silently guessed — see Known limitations.
address
│
▼
Census Bureau Geocoder → county, lat/lon
│
▼
county → HFTD tier lookup (from training data)
│
▼
Open-Meteo 14-day forecast → daily wind speed / gust / humidity
│
▼
trained classifier (per day: tier + weather + month → risk probability)
│
▼
14-day daily risk probabilities
psps_dataset_full.csv combined labeled dataset (324 rows: 162 positive, 162 negative)
psps_dataset.csv positive rows only (real PSPS events)
psps_negative_rows.csv negative rows only (non-events, hard negatives + sampled days)
positive_rows_provenance.csv each positive row traced back to its source PDF report
negative_rows_provenance.csv each negative row traced back to its source (PDF or "sampled")
raw_reports/ the 23 source PG&E PSPS post-event report PDFs
"PSPS dataset - psps_dataset_full.csv" user-edited copy of the dataset (red_flag_warning column removed) — the version actually used for training
model/
train_model.py trains and evaluates the classifier, saves the deployed model
features.py shared feature encoding (one-hot HFTD tier, cyclical month)
psps_model.joblib trained model (gradient boosting)
model_metadata.json feature list, CV/test metrics, county→tier lookup
predict_address.py standalone CLI: address → 14-day risk (geocodes via Nominatim)
test_sanity.py offline sanity checks on model behavior (no network needed)
backend/
main.py FastAPI app — GET/POST /predict
geocode.py address → (county, lat, lon) via the Census Bureau Geocoder
pge_territory.py checks whether a resolved location is inside PG&E's footprint
address_validation.py heuristic: does the input look like a complete street address?
weather.py 14-day forecast via Open-Meteo
risk_model.py loads the trained model, builds feature vectors, predicts
schemas.py Pydantic request/response models
requirements.txt
frontend/
index.html, style.css, app.js PowerRisk web UI (address search, 14-day chart, PG&E map)
map-data.json precomputed CA outline + PG&E territory shape + county positions
Backend (from backend/):
pip3 install -r requirements.txt
uvicorn main:app --port 8000
Try it: curl "http://localhost:8000/predict?address=1155+Pine+St,+Napa,+CA", or open
http://localhost:8000/docs for the interactive API docs.
Frontend (from frontend/), in a second terminal:
python3 -m http.server 5500
Open http://localhost:5500. The frontend calls the backend at http://localhost:8000
(hardcoded as API_BASE at the top of app.js — change it if the backend runs elsewhere).
Retraining the model (from model/), if the dataset changes:
python3 train_model.py
Regenerates psps_model.joblib and model_metadata.json from
../PSPS dataset - psps_dataset_full.csv.
One row = one (county, date). Built from PG&E's own CPUC-filed PSPS post-event reports:
- 162 positive rows — real PSPS events, one row per county affected, extracted from 19 of the 23 source reports (the other 4 reports document a potential shutoff that PG&E ultimately decided not to execute).
- 162 negative rows — 20 "hard negatives" from those same 4 non-event reports (real dates PG&E seriously considered a shutoff but didn't pull the trigger), plus 142 randomly sampled non-event county-days, weighted toward the rainy season for realistic seasonality.
- Weather columns (
wind_speed_mph,wind_gust_mph,humidity_pct) — daily max wind speed, max gust, and minimum relative humidity, pulled from Open-Meteo's historical archive API for each row's specific county and date. hftd_tier— CPUC High Fire-Threat District tier (0 / 2 / 3) for that county, taken from the source report (or, for sampled negative rows, that county's most common tier across the positive data).
Full extraction methodology, per-report caveats, and known discrepancies (e.g. a report's title date vs. the actual de-energization timestamp) are in the provenance CSVs.
Gradient boosting classifier (scikit-learn), chosen by 5-fold cross-validated ROC-AUC over logistic regression, random forest, and gradient boosting. Features: HFTD tier (one-hot), wind speed, wind gust, humidity, and month (cyclical sin/cos encoding).
| Value | |
|---|---|
| Cross-val ROC-AUC | 0.874 ± 0.043 |
| Held-out test ROC-AUC | 0.862 |
| Held-out test accuracy | 75.4% |
| Held-out test precision / recall | 0.71 / 0.84 |
Recall > precision is the intended tradeoff for a safety-adjacent tool — false alarms cost less than missed warnings.
- HFTD tier is county-level, not per-address. The training data only records tier at county granularity (from the PDF reports), so every address in a county gets that county's most common tier, which may over- or under-state risk for a specific circuit.
- Outside PG&E territory is checked, not guessed.
backend/pge_territory.pyrejects addresses in Southern California Edison / SDG&E / LADWP territory (a hardcoded list of the ~9 CA counties PG&E doesn't serve) or outside California entirely, with an explicit error rather than a misleading low-confidence prediction. - In PG&E territory but no incident history (e.g. San Francisco) still predicts, using
a default non-HFTD tier — the API response's
hftd_tier_known: falseflags this; the frontend surfaces it as a warning banner. - The map's "PG&E territory" shape is an approximation — the convex hull of the 32 training counties, not an official boundary file. Labeled as such in the UI.
- ~150-row dataset. Enough to show real signal (see cross-val results above) but small by ML standards. Treat outputs as directional risk, not a calibrated probability.