dfr_psi: PSI stream detector

View source: R/dfr_psi.R

dfr_psiR Documentation

PSI stream detector

Description

Monitors a stream with the Population Stability Index (psi()): the first n_reference observations form the baseline, and every later window of window_size observations is compared with it, feature by feature. Since it monitors the distribution of the observed features, it is primarily used for virtual concept drift, and fits the paper's setting of validating the fields of incoming data files against a baseline file.

Usage

dfr_psi(
  target_feat = NULL,
  n_reference = 1000,
  window_size = 1000,
  bins = 10,
  threshold = 0.25
)

Arguments

target_feat

Names of the columns to be monitored. NULL (the default) monitors every numeric column.

n_reference

Size of the baseline.

window_size

Size of the compared windows (non-overlapping).

bins

Number of quantile groups of the baseline (10 for deciles, 20 for demi-deciles).

threshold

A drift is reported when the PSI of some feature exceeds it. The default, 0.25, is the paper's limit of a significant drift; 0.1 also flags the moderate ones. See psi() for the PSI of samples without drift, which grows as the windows get smaller.

Details

A drift is reported on the last observation of every window whose largest PSI exceeds threshold. reset_state() forgets the baseline, and the next n_reference observations form a new one. Missing values are kept: in the windows they count as observations in no bin (see psi()).

Value

dfr_psi object. After fit(), drifter_output holds the PSI of every feature (⁠psi_<feature>⁠) on the last observation of every window, and obj$reference the baseline.

References

Kurian, J. F. and Allali, M. (2024). Detecting drifts in data streams using Kullback-Leibler (KL) divergence measure for data engineering applications. Journal of Data, Information and Management, 6, 207-216. doi:10.1007/s42488-024-00119-y

Examples

library(daltoolbox)
library(heimdall)
# Scores around 610; from row 3001 half of those above 643 drop by 200.
set.seed(1)
score <- stats::rnorm(5000, 610, 50)
late <- 3001:5000
drop <- late[score[late] > 643 & stats::runif(2000) < 0.5]
score[drop] <- score[drop] - 200
# The PSI reaches about 0.2: a moderate drift, flagged with threshold 0.1.
detector <- dfr_psi(n_reference = 2000, window_size = 500, threshold = 0.1)
model <- fit(detector, data.frame(cbm = score))
model$drifter_output[!is.na(model$drifter_output$psi_cbm), , drop = FALSE]
model$drifted

heimdall documentation built on Dec. 2, 2026, 5:08 p.m.