~/bend-docscommunity

main.bend relies on unsafe/foreign

raw source on the hub · import mlbend-select@0.1.0.0/main.bend as Main

mlbend-select: k-fold cross-validation on top of the split.

import mlbend-select@0.1.0.0/main.bend as Select

The folds are the ones mlbend-split makes, so the two agree by construction: the same seed and the same labels give the same folds. The package adds the walk over the folds — the rows of each fold, the training rows of each fold, and the sizes — so a model can be fitted and scored fold by fold without writing the loop again.

What is proved: every row of the dataset is in exactly one fold (select_covers) — the fold list holds one entry per row, so the folds cover the dataset exactly once each. What is tested: that the fold sizes and the class counts agree with scikit-learn's StratifiedKFold (reference/test_select.py).

2 imports
import Base
import mlbend-split@0.1.1.0/main.bend as Split

Laws

law select_covers provedsource · line 28 · raw

@labels:List<&2, Nat> -> @+orders:List<&2, List<&2, Nat>> -> @+k:Nat -> @+i:Nat -> {0xe8b7953f71ec5b441a90a08e0961269b/main.count_rows(0xe8b7953f71ec5b441a90a08e0961269b/main.folds_from(labels, orders, k, i)) == List.length(&2, Nat, labels) : Nat}

LAW (select_covers): every row of the dataset is in exactly one fold — the fold list holds one entry per row, so the folds cover the dataset exactly once each.

Types

type Fold source · line 22 · raw

Data

Definitions

def fold_of source · line 36 · raw

@+fs:List<&2, Nat> -> @+f:Nat -> Fold

The rows of the fold f: the ones that test and the ones that train.

def fold_size source · line 40 · raw

@fs:List<&2, Nat> -> @f:Nat -> Nat

The number of rows of the fold f.

def fold_sizes_go source · line 44 · raw

@+fs:List<&2, Nat> -> @k:Nat -> @+acc:List<&2, Nat> -> List<&2, Nat>

The number of rows of each fold.

def fold_sizes source · line 52 · raw

@fs:List<&2, Nat> -> @k:Nat -> List<&2, Nat>

The number of rows of each fold.

def folds source · line 56 · raw

@labels:List<&2, Nat> -> @seed:U32 -> @k:Nat -> List<&2, Nat>

The fold of every row of the dataset, in the order of the rows.

def folds_go source · line 60 · raw

@+fs:List<&2, Nat> -> @k:Nat -> @+acc:List<&2, Fold> -> List<&2, Fold>

The rows of every fold.

def folds_of source · line 69 · raw

@labels:List<&2, Nat> -> @seed:U32 -> @+k:Nat -> List<&2, Fold>

The rows of every fold: the test rows of each fold, and the training rows of each fold.