SPB Git

spb/wp39_uqo

Public
662 B · 16 lines python
1import numpy as np2import polars as pl34from wp39.models import Preprocessor567def test_preprocessor_statistics_come_from_train_only():8    tr = pl.DataFrame({"x": [1.0, 2.0, 3.0, 4.0, 100.0], "z": [0.0, 0.0, 1.0, 1.0, 1.0]})9    te = pl.DataFrame({"x": [1000.0, None, -5.0], "z": [5.0, 5.0, 5.0]})10    pp = Preprocessor(["x", "z"]).fit(tr)11    Xte = pp.transform(te)12    assert pp.fitted_on_rows == 513    assert Xte[0, 0] <= (pp.hi["x"] - pp.mu["x"]) / pp.sd["x"] + 1e-9        # clipped at the train 99th percentile14    assert abs(Xte[1, 0] - (pp.med["x"] - pp.mu["x"]) / pp.sd["x"]) < 1e-9  # imputed with the train median15    assert np.all(np.isfinite(Xte))16
Files · main
Menu

Theme