
A product collects several traces from the same handset. Row-level random splitting can put almost identical measurements from one handset in both training and evaluation. The folded output lists device groups in each partition. Each individual group remains entirely on one side of a split.
Set up the evaluation
The small fixtures expose what reaches an estimator after preparation. In deployment, version the transformer, its learned parameters and the feature-column order with the trained model. Recreating these settings from memory can produce a numerically valid but incompatible input.
import numpy as np
from sklearn.model_selection import GroupKFold
def evaluate(v):
return [(sorted(set(np.array(v)[tr])),sorted(set(np.array(v)[te]))) for tr,te in GroupKFold(n_splits=2).split(np.zeros(len(v)),groups=v)]
for sample in [['A', 'A', 'B', 'B', 'C', 'C'], ['P', 'P', 'Q', 'Q'], ['R', 'S', 'S', 'T']]:
print(evaluate(sample))What changes across the three cases
| Example input | Calculated output |
|---|---|
| ["A", "A", "B", "B", "C", "C"] | [[["B"], ["A", "C"]], [["A", "C"], ["B"]]] |
| ["P", "P", "Q", "Q"] | [[["P"], ["Q"]], [["Q"], ["P"]]] |
| ["R", "S", "S", "T"] | [[["R", "T"], ["S"]], [["S"], ["R", "T"]]] |
For ["A", "A", "B", "B", "C", "C"], the observed output is [[["B"], ["A", "C"]], [["A", "C"], ["B"]]]. With ["P", "P", "Q", "Q"], it becomes [[["P"], ["Q"]], [["Q"], ["P"]]]. Compare the two as a before-and-after record. Keeping the input beside the expectation makes it possible to distinguish an intentional contract change from a change introduced by a different parser or runtime.
For ["R", "S", "S", "T"], the operation returns 2 top-level items. An assertion on that count would miss a change in their contents. Capture the expected sequence or compare membership explicitly if order has no meaning in the product.
Keep the shape of these outputs with the recorded result. A list used as a feature vector needs its column order, while a pair of measurements needs a name for each component. A downstream dashboard cannot reconstruct that meaning from a sequence of unlabelled numbers.
What the release review still needs
Independence can also require grouping by user, site or capture session. Choose the grouping unit that matches who or what will be new at deployment.
For a repeatable comparison, retain one counterexample as well as one ordinary success. In this fixture, ["P", "P", "Q", "Q"] makes a useful starting point: its reference result is [[["P"], ["Q"]], [["Q"], ["P"]]]. A changed result is a prompt to inspect the inputs, dependency version and chosen policy before accepting a new baseline.
A reproduction of GroupKFold leakage should keep the fitted transformation with the case. Here the original first input is ["A", "A", "B", "B", "C", "C"]. In a production note, include the exact training rows that established the transformation or split. This makes it possible to tell a code regression apart from a new category or measurement range in the incoming data when the same evaluation is run again.
scikit-learn cross-validation guide · Python numeric types
Sources and further reading
Cover photograph: MacBook Pro 16inti silver model (2026) by Kyu3a. CC BY-SA 4.0. Cropped and typeset for this cover. The photograph illustrates the topic. This image adaptation uses the same share-alike license.
