← Back to projects

DataMaster's thesis2026

Canton-level crime risk index for Ecuador

A composite crime risk index covering every canton in Ecuador, combined with KMeans segmentation and a national forecast benchmarked across six time-series models.

PythonTime seriesLSTMXGBoostPCAKMeans

The question

How can crime risk be compared fairly across cantons when some have millions of residents and others only a few thousand? And once that measure exists, which model best forecasts the national trend?

Approach

1. Canton-level index. Built from Ministry of the Interior open data (homicides, arrests and seized weapons) and INEC population projections:

  • Rates per 10,000 inhabitants.
  • Bayesian shrinkage, so that small cantons don’t look extreme because of random noise: each rate is pulled toward the national mean in proportion to how little data backs it.
  • Indicator weights derived from PCA, combined into a weighted z-score index.
  • A robustness check comparing the index against unadjusted rates and raw counts.

2. Segmentation. KMeans, with the number of clusters chosen using the elbow method, silhouette, Calinski-Harabasz and Davies-Bouldin scores. The result was 6 clusters of cantons with distinct risk profiles.

3. Forecasting. A monthly national index, trained on 2019-2023 and evaluated on 2024-2025, with no information from the test period leaking into training.

Results (test set, 2024-2025)

Model RMSE MAE
Ensemble 0.0871 0.0679
LSTM 0.1169 0.0963
XGBoost 0.1340 0.1102
ETS 0.1361 0.1221
Prophet 0.1501 0.1362
ARIMA 0.1609 0.1486

Stack

pandas, scikit-learn, TensorFlow/Keras, XGBoost, statsmodels, pmdarima and Prophet.