update for 4 hour rain forecast

This commit is contained in:
2026-04-06 18:32:33 +10:00
parent fb50c8ed71
commit 3a7309b2cf
20 changed files with 716 additions and 132 deletions
+18 -7
View File
@@ -1,14 +1,14 @@
# Rain Prediction (Next 1 Hour)
# Rain Prediction (Next 4 Hours)
This project includes a baseline workflow for **binary rain prediction**:
> **Will we see >= 0.2 mm of rain in the next hour?**
> **Will we see >= 0.2 mm of rain in the next 4 hours?**
It uses local observations (WS90 + barometer), trains a logistic regression
baseline, and writes model-driven predictions back to TimescaleDB.
## P0 Decisions (Locked)
- Target: `rain_next_1h_mm >= 0.2`.
- Target: `rain_next_4h_mm >= 0.2`.
- Primary use-case: low-noise rain heads-up signal for dashboard + alert candidate.
- Frozen v1 training window (UTC): `2026-02-01T00:00:00Z` to `2026-03-03T23:55:00Z`.
- Threshold policy: choose threshold on validation set by maximizing recall under
@@ -40,7 +40,7 @@ pip install -r scripts/requirements.txt
- `scripts/train_rain_model.py`: strict time-based split training and metrics report, with optional
validation-only hyperparameter tuning, calibration comparison, naive baseline comparison, and walk-forward folds.
- `scripts/predict_rain_model.py`: inference using saved model artifact; upserts into
`predictions_rain_1h`.
`predictions_rain_4h`.
- `scripts/run_rain_ml_worker.py`: long-running worker for periodic training + prediction.
- `scripts/check_rain_pipeline_health.py`: freshness/failure check for alerting.
- `scripts/recommend_rain_model.py`: rank saved training reports and recommend a deployment candidate.
@@ -60,7 +60,15 @@ Model-family options (`train_rain_model.py`):
## Usage
### 1) Apply schema update (existing DBs)
`001_schema.sql` includes `predictions_rain_1h`.
`003_rain_predictions_4h.sql` adds `predictions_rain_4h`.
```sh
docker compose exec -T timescaledb \
psql -U postgres -d micrometeo \
-f /docker-entrypoint-initdb.d/003_rain_predictions_4h.sql
```
`001_schema.sql` still remains safe to re-run for full schema parity.
```sh
docker compose exec -T timescaledb \
@@ -76,6 +84,8 @@ docker compose exec -T timescaledb \
-f /docker-entrypoint-initdb.d/002_rain_monitoring_views.sql
```
All examples below assume a 4-hour horizon (`--horizon-hours 4`) and `model-name=rain_next_4h`.
### 2) Run data audit
```sh
export DATABASE_URL="postgres://postgres:postgres@localhost:5432/micrometeo?sslmode=disable"
@@ -203,7 +213,8 @@ python scripts/train_rain_model.py \
python scripts/predict_rain_model.py \
--site home \
--model-path "models/rain_model.pkl" \
--model-name "rain_next_1h"
--model-name "rain_next_4h" \
--horizon-hours 4
```
### 5) One-command P0 workflow
@@ -236,7 +247,7 @@ docker compose logs -f rainml
- Model card: `models/model_card_<model_version>.md`
- Model artifact: `models/rain_model.pkl`
- Dataset snapshot: `models/datasets/rain_dataset_<model_version>_<feature_set>.csv`
- Prediction rows: `predictions_rain_1h` (probability + threshold decision + realized
- Prediction rows: `predictions_rain_4h` (probability + threshold decision + realized
outcome fields once available)
### 7) Recommend deploy candidate from saved reports