Przejdź do treści
Biblioteka skilli
Dane i analityka · Przegląd i audyt

ml-data-leakage

/ml-data-leakage

Zapobiega wyciekowi danych testowych do treningu przy podziale zbioru, preprocessingu i walidacji krzyżowej.

Repozytorium
trainlint ↗
Licencja
MIT
Ostatnia zmiana repozytorium
03.11.2026

Ocena i bezpieczeństwo

100/ 100Klasa: dobry
Format25 / 25
Frontmatter z nazwą i opisem, poprawna nazwa, opis do 1024 znaków, nazwa zgodna z folderem.
Odkrywalność25 / 25
Opis mówi, kiedy użyć skilla, ma sensowną długość i jest w 3. osobie.
Treść35 / 35
Co najmniej 150 słów i do 500 linii, nagłówki, listy kroków, przykłady albo kod.
Higiena15 / 15
Bez zaślepek typu TODO, bez ścieżek Windows, z licencją.
Ryzykobrak sygnałów w skanie
Pliki w paczce
1
Skrypty
0
Komentarze HTML
0
Adresy URL w SKILL.md
0
Przestarzałość

Brak sygnałów. Repozytorium zmienione 03.11.2026, bez odwołań do wycofanych modeli i API.

Licencja

MIT, otwarta: można używać i zmieniać, z zachowaniem informacji o autorze.

Co robi i kiedy

Zapobiega wyciekowi danych testowych do treningu przy podziale zbioru, preprocessingu i walidacji krzyżowej.

Oryginalny opis (EN)

Prevents train/test leakage when writing or reviewing machine learning code. Use when splitting data, building preprocessing or feature selection steps, setting up cross-validation, oversampling, or when a validation score looks too good. Covers scalers, encoders, imputers, SelectKBest, SMOTE, target encoding, time series and grouped data.

Jak działa

  1. Rules
  2. Patterns
  3. Check a suspicious score
  4. Check the code
Sekcje z nagłówków SKILL.md, w oryginale · 71 linii, 494 słów
Podgląd SKILL.md
---
name: ml-data-leakage
description: Prevents train/test leakage when writing or reviewing machine learning code. Use when splitting data, building preprocessing or feature selection steps, setting up cross-validation, oversampling, or when a validation score looks too good. Covers scalers, encoders, imputers, SelectKBest, SMOTE, target encoding, time series and grouped data.
---

# Data leakage

Leakage means information from validation or test rows reached the model during training. The
score goes up and real-world performance does not. It never raises an error, so it has to be
prevented by construction.

To see the size of the effect: selecting the best 20 of 5,000 random features on the full dataset
and then cross-validating reports about 88% accuracy on labels that are coin flips. The same
steps inside a pipeline report 50%.

## Rules

1. Split first. Anything learned from data is fitted on the training split only: scaler means,
   imputer values, vocabularies, PCA components, selected features, class weights, resampling.
   Apply it to the other splits with `transform()`.
2. For cross-validation, put preprocessing and feature selection inside a `Pipeline` and pass the
   pipeline to `cross_val_score` or `GridSearchCV`. The pipeline refits every step on each fold.
3. Oversample (SMOTE, duplication) and augment the training split only, after splitting. A
   resampled copy of a row in the test set is a copy of a training row.
4. Match the split to how the model will be used:
   - Rows that share a person, patient, device, session, or document go through
     `GroupKFold` or `GroupShuffleSplit` with that id.
   - Time-ordered data is split by time (`TimeSeriesSplit`), never shuffled, and features use only
     the past.
   - Exact and near duplicates are dropped before splitting or split by a group key.
5. Exclude columns that are computed from the label or recorded after the outcome. A feature that
   dominates the importances deserves suspicion before it deserves credit.
6. Use the test set once. Choose models, thresholds and epoch counts on validation data and
   report on test data a single time at the end.
7. Target encoding and any feature built from the label are computed inside each training fold.
8. Fit tokenizers, vocabularies and normalization statistics on the training split. Pretrained
   embeddings are fine.

## Patterns

```python
# Wrong: the scaler has seen the test rows.
X = StandardScaler().fit_transform(X)
X_train, X_test, y_train, y_test = train_test_split(X, y)

# Right.
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=0)
scaler = StandardScaler().fit(X_train)
X_train, X_test = scaler.transform(X_train), scaler.transform(X_test)
```

```python
# Right for cross-validation: every step is refit per fold.
pipe = make_pipeline(SelectKBest(f_classif, k=20), LogisticRegression())
scores = cross_val_score(pipe, X, y, cv=5)
```

```python
# Oversample after the split, on the training part only.
X_train, y_train = SMOTE(random_state=0).fit_resample(X_train, y_train)
```

## Check a suspicious score

Run the same pipeline with the labels shuffled (`rng.permutation(y)`). A leak-free pipeline scores
at chance. If it scores clearly above chance, something is leaking.

## Check the code

If `trainlint` is installed, run `trainlint check <file>` after editing. TL001 flags
preprocessing fitted before a split, TL002 flags fits on validation or test data and TL013
flags rescaling by a dataset's own statistics before it is split. Fix each
finding, or add `# trainlint: ignore[TL001]` with a comment saying why it does not apply. If it is
not installed, apply the rules above by hand.

Wersje

W bazie nie ma innych skilli o nazwie ml-data-leakage.

Migawka bazy z 13.11.2026 · wersja paczki 4366746400e8 (skrót SHA-256 całej paczki)

Pobrania w ostatnich 30 dniach: 2 · ranking

Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.

Podobne skille

  • 95ml4t-data-leakage
    Zapobiega przeciekom danych: kontaminacji zbioru testowego, wyciekowi celu i wyciekowi czasowemu, przy dzieleniu danych, dopasowywaniu preprocesorów i budowie cech dla szeregów czasowych.
  • 90leakage
    Pilnuje zasad unikania wycieku danych w uczeniu maszynowym: podziałów czasowych i grup, przetwarzania wstępnego i zbioru testowego.
  • 90ml-leakage-check
    Przegląda preprocessing i potoki cech ML pod kątem wycieku celu, gdy metryki walidacyjne wyglądają podejrzanie dobrze lub transformery uczą się przed podziałem danych.
  • 100leakage-hunter
    Sprawdza modele ML przed podaniem wyniku: zduplikowane wiersze między zbiorami, wyciek celu, błędy kolejności czasowej i przygotowanie danych dopasowane przed podziałem.
  • 100data-preparation
    Czyści, łączy i dzieli dane bez przecieku: kontrole liczby wierszy, deduplikacja, imputacja, podziały train, test i walidacja, także czasowe.
  • 90designing-leakage-safe-experiments
    Projektuje eksperymenty uczenia maszynowego odporne na wyciek danych, które odzwierciedlają realne wdrożenie: moment predykcji, dobór cech, podziały train-validation-test, bazowe punkty odniesienia i metryki.

Uwagi i zgłoszenia

Wiadomość trafi do Bartosza Sokolińskiego. Adres e-mail jest potrzebny tylko do odpowiedzi. Szczegóły w polityce prywatności.