Skip to content

limen-ml

Documentation ยท Changelog

limen-ml is the machine learning of Limen, an open early-warning system for landslides, floods and wildfires in Italy: it trains a hazard model on spatial folds, calibrates it, tells when the world has drifted from its data, and serves a small network over a week of rain.

pip install "limen-ml[train]"         # LightGBM, scikit-learn, Optuna, SHAP
pip install "limen-ml[serve]"         # onnxruntime, to score with the rainfall network
pip install "limen-ml[dl]"            # PyTorch, to train it
from limen_ml import folds, matrix, metrics, train

m = matrix.to_matrix(samples, ("static.slope_deg", "rain.rain_72h_mm", "insar.velocity_mmy"))
k = folds.spatial_block_folds(list(m.groups), 5, rng_seed=42)

best = train.tune(m, k, trials=50, seed=42)
cv = train.cross_validate(m, k, best)  # AUC-PR, Brier, out-of-fold probabilities
calibrator = train.fit_isotonic(cv.oof_prob, cv.y)
model = train.fit_final(m, best, seed=42)
print(cv.auc_pr_mean, metrics.conformal_quantiles(cv.y, calibrator.transform(cv.oof_prob)))

A sample is anything with features (blocks of numbers), label (0/1) and split_block (its spatial block).

The rules

  • Spatial folds, the same for every model. Two cells a kilometre apart share their rain and their rock: a random split measures memory. Whole blocks go to one fold, and every algorithm is compared on the same folds.
  • AUC-PR, not accuracy. Landslides are one row in many; the area under the precision-recall curve stays honest where accuracy does not.
  • Not measured stays not measured. The application says which absent feature is NaN (a cell the satellite does not see is not a still slope) and which is a true zero; the logistic reference imputes with a "was missing" column.
  • A linear reference. A standardised logistic regression runs next to the boosted trees: if they do not beat it, the non-linear structure buys nothing.
  • Reproducible. Seeded search and folds, deterministic LightGBM, and a matrix hash on values rounded to nine decimals, so threads do not change it.
  • No database, no tracking, no schema. The application brings its samples, its feature schema and its baselines, and logs where it wants.
  • Checked against the code it replaces. Every function that comes from Limen is compared with Limen's own, frozen in tests/limen_reference.py.
  • A model never decides an alert. It is a challenger, promoted only by a person after a backtest. The official warning is the criticality bulletin of the Civil Protection Department.

Develop

make help    # the targets
make check   # ruff, mypy --strict, pytest: the gate CI runs

Licence

Code: Apache-2.0.