0Pricing
MLOps Academy · Lekcja

Pomiar driftu za pomocą PSI i KS

Kwantyfikuj zmianę rozkładu dla każdej cechy

Pomiar driftu za pomocą PSI i KS to bezpłatna lekcja MLOps Academy na CoddyKit. To lekcja 2 z 4. Możesz przeczytać całą lekcję poniżej za darmo — a potem ćwiczyć ją interaktywnie w przeglądarce z wbudowanym edytorem kodu i tutorem AI dostępnym 24/7. To część ścieżki edukacyjnej MLOps Academy, a Twój postęp synchronizuje się między webem a aplikacją CoddyKit. Kurs MLOps Academy zawiera 4 lekcji w sumie.

Części tej lekcji nie zostały jeszcze przetłumaczone i są wyświetlane po angielsku.

From Hunch to Number

Saying a feature feels different is not enough. You need a number that says how much its distribution moved. Two trusted tools are PSI and the KS test. 📏

What PSI Measures

The Population Stability Index compares a feature now against training, bin by bin. The bigger the gap in each bin, the higher the score.

Reading PSI Values

A common rule of thumb: PSI below 0.1 means stable, 0.1 to 0.25 means moderate shift, and above 0.25 means significant drift worth acting on.

How PSI Is Computed

For each bin, PSI takes the percent difference times the log ratio of the two percentages, then sums across all bins into one score.

import numpy as np

def psi(expected, actual):
    return np.sum((actual - expected) * np.log(actual / expected))

Binning Comes First

PSI needs both samples placed into the same bins, often deciles of the training data. Same edges for both sides keep the comparison fair.

edges = np.quantile(reference, np.linspace(0, 1, 11))
exp = np.histogram(reference, edges)[0] / len(reference)
act = np.histogram(current, edges)[0] / len(current)

What the KS Test Measures

The Kolmogorov-Smirnov test finds the largest gap between two cumulative distributions. That maximum distance is the KS statistic.

KS in One Line

SciPy gives you the KS test directly. A small p-value means the two samples likely come from different distributions, hinting at drift.

from scipy.stats import ks_2samp

stat, pvalue = ks_2samp(reference, current)
drifted = pvalue < 0.05

PSI vs KS

PSI gives a single severity score great for dashboards. KS gives a statistical p-value great for yes-or-no decisions. Many teams track both side by side.

Categorical Features

PSI works naturally on categories, treating each value as its own bin. KS assumes ordered numbers, so reach for chi-square on categorical features instead.

Watch the Sample Size

With huge samples the KS test flags tiny, harmless shifts as significant. Pair its p-value with an effect size like PSI before you raise an alarm.

Per-Feature, Then Roll Up

Run these tests per feature, then summarize. A handy signal is the share of features that drifted, which tells you if the shift is broad or narrow. 📊

Quick Check

Pick the right read on these numbers.

Recap

You turned drift into numbers: PSI scores severity with bins, KS measures the biggest distribution gap. Use both, mind sample size, and pick the right test per feature type. 🎯

Często zadawane pytania

Czy lekcja „Pomiar driftu za pomocą PSI i KS” jest bezpłatna?

Tak — pełny tekst „Pomiar driftu za pomocą PSI i KS” jest dostępny za darmo tutaj w sieci. Aby ćwiczyć ją interaktywnie (wbudowany edytor kodu i tutor AI dostępny 24/7) i odblokować resztę kursu MLOps Academy, przejdź na CoddyKit PRO. Kurs MLOps Academy zawiera 4 lekcji w sumie.

Co nauczysz się w „Pomiar driftu za pomocą PSI i KS”?

Kwantyfikuj zmianę rozkładu dla każdej cechy Ćwiczysz MLOps Academy z praktycznym kodem, który uruchamiasz bezpośrednio w przeglądarce, a tutor AI dostępny 24/7 odpowiada na Twoje pytania podczas pracy nad lekcją.

Czy potrzebuję doświadczenia, aby zacząć MLOps Academy?

Nie wymagamy żadnego doświadczenia. MLOps Academy w CoddyKit jest strukturyzowany dla początkujących i zaawansowanych użytkowników, więc możesz zacząć tutaj lub od początku i uczyć się w swoim tempie. To lekcja 2 z 4.

Ile czasu zajmuje lekcja „Pomiar driftu za pomocą PSI i KS”?

Większość lekcji CoddyKit trwa około 5–10 minut. Każda lekcja to mały, interaktywny krok, dzięki czemu robisz systematyczne postępy i zawsze wracasz dokładnie do tego samego miejsca — na webie i w aplikacji.

Czy mogę pisać i uruchamiać kod w tej lekcji MLOps Academy?

Tak. Każda lekcja MLOps Academy zawiera wbudowany edytor kodu, więc piszesz i uruchamiasz prawdziwy kod bezpośrednio w przeglądarce i od razu otrzymujesz sprzężenie zwrotne od AI — bez konfiguracji na komputerze.

Wszystkie lekcje w tym kursie

  1. Drift danych a drift pojęcia
  2. Pomiar driftu za pomocą PSI i KS
  3. Generowanie raportów driftu za pomocą Evidently
  4. Ustawianie progów i wyzwalaczy driftu
← Powrót do MLOps Academy