Rule-Based Flood Risk Dashboard Beats ML on Small Weather Data

Switch from unstable Random Forest ML to rule-based scoring on OpenWeather rainfall (<20mm low, 55-100mm high), humidity, and wind for stable LOW/MEDIUM/HIGH flood risk; visualize trends, maps, and metrics in interactive Streamlit app.

Rule-Based Scoring Delivers Stable, Interpretable Flood Risk

Flood risk emerges from accumulated rainfall over 24 hours, not just instant rates—calculate it with df['rain_24h'] = df['rainfall'].rolling(8).sum() since API data arrives every 3 hours (8 points = 24h). Score total risk (0-100) using rainfall as primary driver: <20mm low contribution, 20-55mm moderate, 55-100mm high, >100mm very high; amplify with high humidity and strong winds as supporting factors. Classify final score as LOW (<30), MEDIUM (30-70), HIGH (≥70). This outperforms Random Forest ML on small, imbalanced API datasets lacking stable flood labels—rules stay interpretable (trace exact risk drivers), adjustable via domain knowledge, and immune to training variance. Handle missing rainfall with fallbacks to avoid crashes.

Interactive Controls and Visuals Turn Data into Actionable Insights

Sidebar filters drive everything: st.sidebar.selectbox for province (cascades to cities via province_map[selected_province]), multiselect for risk levels (filter if risk not in risk_filter: continue), checkboxes for heatmap/markers. Trends reveal dynamics—line charts for rainfall spikes (px.line(df, x='datetime', y='rainfall')), 24h accumulation (catches sustained rain), and risk probability (px.line(df, x='datetime', y='ml_proba') despite rule basis). Metrics offer instant reads: max 24h rainfall, current humidity/wind via st.metric. Maps add spatial context—Folium CircleMarkers color-coded by risk (red >70, orange >40, green), toggleable Province (multi-city compare) vs Single City views with st.radio, plus HeatMap for risk density (HeatMap(heat_data).add_to(m)). Bottom table previews raw data (st.dataframe(df.tail(n)) with n=5/10/20/30 selectbox) for verification.

Deploy Securely on Streamlit Cloud for Real-Time Monitoring

Fetch multi-city OpenWeather 3-hour forecasts (rainfall, humidity, wind) via API, but separate calls per city slow performance—cache where possible. Use Streamlit secrets (API_KEY = st.secrets["API_KEY"]) to hide keys, push app.py/requirements.txt to GitHub, link in Streamlit Cloud for auto-deploys. This yields a live dashboard at indonesia-flood-risk-dashboard.streamlit.app/ focused on Indonesia's urban flood-prone areas, evolving from basic viz to risk prediction without complex models.

Summarized by x-ai/grok-4.1-fast via openrouter

6534 input / 1834 output tokens in 13947ms

© 2026 Edge