Spatial folds¶
limen_ml.folds ¶
Spatial blocks for cross-validation: no fold learns from its neighbours.
Two cells a kilometre apart share their rain, their rock and often their
landslides. A random split would put one in training and the other in
validation and measure memory, not skill. Cells are grouped into coarse
blocks (:class:SpatialBlockGrid) and whole blocks go to one fold.
SpatialBlockGrid
dataclass
¶
A coarse grid of square blocks of edge_deg degrees.
block_for ¶
block_for(lon: float, lat: float) -> str
The block id "{lon_index}|{lat_index}" of a point.
spatial_block_folds ¶
spatial_block_folds(blocks: Sequence[str], k: int, *, rng_seed: int = 42) -> list[list[str]]
blocks into k disjoint folds, round-robin after a seeded shuffle.
fold_index ¶
fold_index(groups: Sequence[str], folds: Sequence[Sequence[str]]) -> Any
The fold of each row, from its block; a block in no fold goes to fold 0.
class_weight ¶
class_weight(y: Any) -> dict[int, float]
Inverse-frequency weights of the two classes, for the heavy 0/1 imbalance.