File size: 4,868 Bytes
099d46e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# T2.3 Β· Grid Outage Forecaster + Appliance Prioritizer
**AIMS KTT Fellowship Hackathon 2026**

Predict 24-hour grid outage probability and generate actionable load-shedding plans for SMEs β€” designed for low-bandwidth, offline-first, non-smartphone users in Rwanda.

---

## ⚑ Quickstart (≀ 2 commands, free Colab CPU)

```bash
pip install pandas numpy scikit-learn lightgbm
python generate_data.py && python prioritizer.py salon
```

That's it. Generates all data, fits the model, prints the 24h plan and SMS digest for the salon archetype.

---

## πŸ“Š Evaluation Metrics (30-day held-out)

| Metric | Value | Baseline |
|--------|-------|----------|
| Brier Score (P outage) | **0.1756** | 0.212 (naΓ―ve rate) |
| Duration MAE | **61.2 min** | β€” |
| Avg Lead Time | **2.79 h** | β€” |
| Inference Latency | **< 300 ms CPU** | β€” |
| Retrain Time | **< 5 min** | β€” |

---

## πŸ“ Repository Structure

```
β”œβ”€β”€ generate_data.py      # Synthetic data generator (reproducible, seed=42)
β”œβ”€β”€ forecaster.py         # LightGBM probabilistic outage forecaster
β”œβ”€β”€ prioritizer.py        # Constrained appliance load-shedding planner
β”œβ”€β”€ lite_ui.html          # Static 50KB dashboard (open in any browser)
β”œβ”€β”€ digest_spec.md        # Product & Business adaptation artifact
β”œβ”€β”€ process_log.md        # Hour-by-hour timeline + LLM tool use
β”œβ”€β”€ SIGNED.md             # Honor code (signed)
β”œβ”€β”€ eval.ipynb            # Rolling evaluation notebook
β”œβ”€β”€ grid_history.csv      # Generated: 180 days Γ— hourly grid data
β”œβ”€β”€ appliances.json       # 10 appliances with categories + revenue
└── businesses.json       # 3 business archetypes (salon, cold room, tailor)
```

---

## πŸ”§ Usage

### Generate data
```bash
python generate_data.py
# β†’ grid_history.csv, appliances.json, businesses.json
```

### Run forecast (CLI)
```bash
python forecaster.py                    # 24h forecast preview
python forecaster.py --eval             # Rolling 30-day Brier + MAE
python forecaster.py --serve            # JSON output + latency
```

### Run appliance plan
```bash
python prioritizer.py salon             # Salon archetype
python prioritizer.py cold_room         # Cold room archetype
python prioritizer.py tailor            # Tailor archetype
```

### Open UI
```bash
# Just open lite_ui.html in any browser β€” no server needed
```

---

## πŸ—οΈ Architecture

```
grid_history.csv
      β”‚
      β–Ό
forecaster.py::build_features()   ← lag features, rolling stats, weather, temporal
      β”‚
      β–Ό
LightGBM Classifier β†’ P(outage) per hour
LightGBM Regressor  β†’ E[duration | outage] per hour
      β”‚
      β–Ό
prioritizer.py::plan()
  Shed order: luxury β†’ comfort β†’ critical
  Tie-break: lowest revenue-per-hour shed first
  Exception: critical protected during peak hours
      β”‚
      β–Ό
lite_ui.html   (forecast chart + appliance grid + SMS digest)
```

---

## 🌍 Product & Business Design

Designed for **low-bandwidth, offline-first, non-smartphone users**:

- **Feature phone SMS digest** (3 Γ— 160 chars) at 06:30 CAT β€” no internet required for the end user
- **Offline fallback**: cached plan valid 6h, staleness banner after that, plan expired after 8h
- **Illiteracy adaptation**: Colored LED relay board (ESP32 + 3-channel relay, ~USD 8/unit) β€” red/green/yellow per appliance slot, no reading required
- **Cost**: ~RWF 30/business/day all-in (SMS + server amortized across 200+ subscribers)
- **Revenue protected**: ~RWF 62,000/week per salon vs naΓ―ve full-on operation

See `digest_spec.md` for full specification with numbers, users, and workflows.

---

## πŸ“Ή 4-Minute Video

[YouTube link β€” to be inserted before submission]

**Video structure:**
- 0:00–0:30 On-camera intro: name, challenge ID, Brier score 0.1756
- 0:30–1:30 Live code: `prioritizer.py::plan()` β€” critical-before-luxury logic
- 1:30–2:30 Live demo: `lite_ui.html` salon forecast + plan
- 2:30–3:30 Read `digest_spec.md` morning SMS aloud
- 3:30–4:00 Three spoken answers

---

## πŸ€– Model Hosting

Model weights (LightGBM pkl files) hosted on Hugging Face Hub:  
`[HF link β€” to be inserted before submission]`

Alternatively, retrain from scratch in < 5 min:
```bash
python forecaster.py --fit
```

---

## πŸ“œ License

MIT License β€” see LICENSE file.

---

## βœ… Submission Checklist

- [x] Public GitHub repo with README
- [x] `generate_data.py` β€” reproducible in 2 commands
- [x] `forecaster.py` + `prioritizer.py`
- [x] `lite_ui.html` β€” < 50KB static page
- [x] `eval.ipynb` β€” rolling 30-day metrics
- [x] `digest_spec.md` β€” Product & Business artifact with real numbers
- [x] `process_log.md` β€” timeline + LLM use declared
- [x] `SIGNED.md` β€” honor code signed
- [ ] 4-minute video URL (to be added)
- [ ] Hugging Face model card link (to be added)