The Kolmogorov-Smirnov (KS) test is a non-parametric statistical hypothesis test that quantifies the distance between the empirical distribution functions of two samples. It is a foundational method for univariate drift detection, comparing a reference dataset (e.g., training data) against a production dataset to determine if their underlying distributions differ significantly. The test's primary output is the KS statistic (D), which is the maximum vertical distance between the two cumulative distribution functions, and a p-value indicating the significance of this difference.
Glossary
Kolmogorov-Smirnov Test (KS Test)

What is the Kolmogorov-Smirnov Test (KS Test)?
A non-parametric statistical test used to detect univariate data drift by comparing two one-dimensional probability distributions.
In machine learning operations, the KS test is applied per feature to monitor for covariate shift. It is sensitive to differences in both the shape and location of distributions but is limited to one-dimensional, continuous data. For multivariate drift, metrics like Jensen-Shannon Divergence are used. A calculated drift score exceeding a predefined drift threshold can trigger an automated retraining trigger or alert, forming a core component of data observability and quality posture.
Key Characteristics of the KS Test
The Kolmogorov-Smirnov (KS) test is a non-parametric statistical test that quantifies the distance between two empirical cumulative distribution functions (ECDFs). Its core properties make it a foundational tool for univariate data drift detection.
Non-Parametric Nature
The KS test is a non-parametric test, meaning it makes no assumptions about the underlying distribution of the data (e.g., normality). It operates directly on the empirical cumulative distribution function (ECDF). This makes it robust and widely applicable for comparing any continuous or discrete one-dimensional data.
- Key Advantage: No need to know or estimate distribution parameters.
- Use Case: Ideal for monitoring production data where the true distribution is unknown or complex.
The KS Statistic (D)
The test's output is the KS statistic, denoted as D. It is the maximum vertical distance between the two empirical cumulative distribution functions being compared.
- Calculation: (D = \sup_x | F_{reference}(x) - F_{production}(x) |), where (F) is the ECDF.
- Interpretation: A D value of 0 indicates identical distributions. Larger D values (closer to 1) indicate greater divergence.
- Example: A D statistic of 0.15 means the two ECDFs differ by at most 15 percentage points at their point of maximum separation.
Sensitivity to Location and Shape
The KS test is sensitive to differences in both the location (e.g., mean, median) and the shape (e.g., variance, skewness) of the two distributions. Because it measures the maximum distance across the entire range of the variable, it can detect:
- Shifts in the median.
- Changes in spread (variance).
- Differences in skewness.
Limitation: It is generally less sensitive to differences in the tails of the distribution compared to dedicated tail-sensitivity tests.
Univariate and Two-Sample Focus
The standard KS test is designed for univariate, two-sample comparisons. This defines its primary role in data drift detection.
- Univariate: It analyzes one feature (variable) at a time. To monitor a model with multiple features, a KS test must be run independently on each, potentially requiring multiplicity corrections.
- Two-Sample: It requires two distinct datasets: a reference dataset (e.g., training data) and a target/production dataset.
- Contrast: It is not inherently a multivariate test and cannot directly capture correlation shifts between features.
The p-value and Hypothesis Test
The KS test formalizes drift detection as a statistical hypothesis test.
- Null Hypothesis (H0): The two samples are drawn from the same underlying distribution.
- Alternative Hypothesis (H1): The two samples are drawn from different distributions.
- p-value: The probability of observing a KS statistic (D) as extreme as the one calculated, assuming H0 is true. A small p-value (e.g., < 0.05) provides evidence to reject H0 and signal significant drift.
Critical Note: In large-scale production data, sample sizes are often enormous, leading to extremely small p-values for even minor, operationally insignificant shifts. Therefore, the D statistic is often a more practical drift metric than the p-value.
Comparison to PSI and Other Metrics
The KS test is one of several metrics for univariate drift. Key comparisons:
- vs. Population Stability Index (PSI): PSI bins data and compares bin proportions. KS uses the full ECDF without binning, making it more sensitive to shifts within bins. PSI is more common in finance for monitoring score distributions.
- vs. Wasserstein Distance: Wasserstein distance measures the "work" needed to transform one distribution into another. It can be more intuitive for continuous distributions and is often more sensitive to tail differences.
- vs. Jensen-Shannon Divergence: JSD measures the similarity between distributions and is useful for multivariate drift when applied to lower-dimensional projections.
Best Practice: The KS test is a strong default for continuous features, but the choice of metric should align with the specific sensitivity required (e.g., tail events, central tendency).
KS Test vs. Other Drift Detection Methods
A feature comparison of the Kolmogorov-Smirnov test against other common statistical methods for detecting univariate data drift.
| Feature / Metric | Kolmogorov-Smirnov (KS) Test | Population Stability Index (PSI) | Jensen-Shannon Divergence (JSD) | Wasserstein Distance |
|---|---|---|---|---|
Primary Use Case | Comparing two empirical cumulative distribution functions (ECDFs) | Comparing binned distributions, common in finance and credit risk | Measuring similarity between two probability distributions | Measuring distance between two continuous distributions |
Data Type Compatibility | Continuous, ordinal | Categorical, binned continuous | Continuous, discrete (with smoothing) | Continuous |
Output Range | 0 to 1 (D-statistic) | 0 to ∞ (typically < 0.25 is stable) | 0 to 1 (symmetric, bounded) | 0 to ∞ (depends on data scale) |
Sensitive To | Differences in the shape/location of the entire distribution | Differences in bin probabilities, especially in tails | Overall distribution shape (smoothed KL Divergence) | Differences requiring mass to be 'moved' |
Multivariate Extension | ||||
Common Drift Threshold | D-statistic > 0.1 | PSI > 0.1 | JSD > 0.1 | Context-dependent; no universal threshold |
Computational Complexity | O(n log n) for sorting | O(n + b) for b bins | O(n) with kernel density estimation | O(n^3) for exact, O(n log n) approximations |
Handles Streaming/Online Data |
Common Applications in Machine Learning
The Kolmogorov-Smirnov (KS) test is a foundational non-parametric statistical method for comparing one-dimensional probability distributions. Its primary application in machine learning is the detection of univariate data drift by quantifying the difference between a reference dataset (e.g., training data) and a production dataset.
Core Statistical Mechanism
The KS test quantifies the distance between two empirical cumulative distribution functions (ECDFs). For two samples, it calculates the maximum vertical distance (D-statistic) between their ECDFs. This D-statistic, along with the sample sizes, is used to compute a p-value to test the null hypothesis that the two samples are drawn from the same underlying distribution.
- Non-parametric: Makes no assumptions about the underlying distribution shape (e.g., normal, uniform).
- Sensitive to location, scale, and shape: Can detect differences in median, variance, and skewness.
- One-dimensional: Operates on a single feature at a time, making it a univariate drift detection method.
Univariate Feature Drift Detection
This is the most common ML application. The KS test is applied independently to each feature (column) in a dataset to monitor for distributional shifts.
Process:
- Define a Reference Distribution: The ECDF is calculated for each feature using the training dataset or a trusted historical snapshot.
- Calculate a Production Distribution: The ECDF is calculated for the same feature using a recent batch of production inference data.
- Compute the KS Statistic: The maximum distance (D) between the two ECDFs is found.
- Alert on Drift: If the D-statistic exceeds a pre-defined drift threshold or the p-value falls below a significance level (e.g., 0.05), an alert is triggered for that feature.
This allows data scientists to pinpoint exactly which features have changed, aiding in root cause analysis.
Model Input (Covariate) Monitoring
The KS test is specifically suited for detecting covariate shift, where the distribution of input features P(X) changes between training and production, while the relationship P(Y|X) remains stable.
Example: A model trained to predict credit risk using applicant income data from 2020 may see its input distribution shift if applied to applicants in 2024 due to economic inflation. A KS test on the 'income' feature would detect this shift, signaling potential model decay even before performance metrics degrade.
Key Consideration: It cannot detect concept drift, where P(Y|X) changes, as it only analyzes the feature distributions X, not the relationship to the target Y.
Label Drift Analysis
The KS test can be applied to monitor the distribution of the target variable (label), especially in classification tasks with numeric scores or regression problems.
For Binary Classification: If a model outputs a prediction score (probability between 0 and 1), the KS test can compare the distribution of scores for the positive class between reference and production data. A significant drift may indicate a change in the underlying class prevalence or the model's calibration.
For Regression: The distribution of the actual target values (e.g., house prices, transaction amounts) can be monitored for drift. A shift suggests a change in the environment the model is predicting, which likely necessitates model retraining.
Model Output & Error Distribution Monitoring
Beyond raw features, the KS test can monitor the distributions of model predictions and prediction errors (residuals).
- Prediction Drift: A shift in the distribution of model outputs may indicate covariate shift or early concept drift.
- Residual Drift: In regression, the distribution of errors (actual - predicted) should ideally be consistent. A KS test detecting a change in the residual distribution is a strong signal of model performance degradation and potential concept drift, as the model's mistakes are becoming systematically different.
Strengths, Limitations & Practical Notes
Strengths:
- Simple & Interpretable: The D-statistic is easy to understand (max difference between CDFs).
- Distribution-free: Robust to non-normal data.
- Sensitive to all distribution differences: Good for exploratory drift detection.
Limitations & Considerations:
- Univariate Only: Cannot detect drift in correlations between features (multivariate drift). Must be combined with methods like Jensen-Shannon Divergence (JSD) or Wasserstein Distance for a full picture.
- Sensitive to Sample Size: With very large datasets, even tiny, inconsequential distribution differences can yield statistically significant p-values. Drift thresholds should often be set based on the D-statistic's business impact, not just p < 0.05.
- Discrete/Categorical Data: The standard KS test is for continuous data. For categorical features, use the Chi-Square test or a specialized adaptation.
- Batch-Based: Typically used for offline drift detection on accumulated data batches. For online drift detection in streams, algorithms like ADWIN or Page-Hinkley are more suitable.
Frequently Asked Questions
The Kolmogorov-Smirnov (KS) test is a cornerstone non-parametric statistical method for detecting univariate data drift. This FAQ addresses its core mechanics, applications in machine learning operations, and its relationship to other drift detection techniques.
The Kolmogorov-Smirnov (KS) test is a non-parametric statistical hypothesis test used to determine if two one-dimensional probability distributions differ, making it a fundamental tool for detecting univariate data drift. It works by comparing the empirical cumulative distribution functions (ECDFs) of two samples—typically a reference dataset (e.g., training data) and a production dataset. The test statistic, denoted D, is the maximum absolute vertical distance between the two ECDFs. A larger D indicates a greater divergence between the distributions. The p-value derived from D determines if the observed difference is statistically significant, allowing practitioners to reject the null hypothesis that the two samples are drawn from the same distribution.
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Related Terms
The Kolmogorov-Smirnov test is one of several statistical methods used to identify distributional changes in data. These related concepts provide context for its application within a broader data observability framework.
Population Stability Index (PSI)
The Population Stability Index (PSI) is a statistical measure used to quantify the shift between two distributions by comparing the expected (reference) and actual (production) proportions of data across binned categories. It is a common alternative to the KS test for univariate drift detection, particularly in financial and risk modeling.
- Calculation: PSI = Σ (Actual % - Expected %) * ln(Actual % / Expected %)
- Interpretation: Values < 0.1 indicate minimal change, 0.1-0.25 indicate moderate drift, and > 0.25 indicate a significant shift requiring investigation.
- Key Difference from KS Test: PSI requires data binning, making it sensitive to bin selection, while the KS test is non-parametric and works on the cumulative distribution function.
Jensen-Shannon Divergence (JSD)
Jensen-Shannon Divergence (JSD) is a symmetric, smoothed measure of similarity between two probability distributions, derived from the Kullback-Leibler divergence. It is commonly used for multivariate data drift detection, where the KS test (a univariate method) is insufficient.
- Properties: JSD is bounded between 0 (identical distributions) and 1 (maximally different), and its square root is a proper metric.
- Multivariate Application: By comparing the JSD of feature vectors or model prediction distributions, it can detect complex, correlated shifts across multiple dimensions.
- Comparison to KS: While the KS test is powerful for one-dimensional, continuous data, JSD is better suited for high-dimensional or discrete data where understanding the joint distribution is critical.
Covariate Shift
Covariate shift is a specific type of data drift where the distribution of the input features (P(X)) changes between the training and production environments, while the conditional relationship between features and the target (P(Y|X)) remains stable. Detecting covariate shift is a primary use case for the KS test.
- Real-World Example: A credit scoring model trained on data from one geographic region may experience covariate shift when deployed in another, where income distributions differ.
- Detection Method: The KS test is applied feature-by-feature to compare the training (reference) and production distributions, flagging individual covariates that have shifted significantly.
- Impact: Even with a stable P(Y|X), covariate shift can degrade model performance if the production data contains regions of feature space not well-represented during training.
Univariate vs. Multivariate Drift
This distinction categorizes drift detection methods based on whether they analyze features individually or jointly. The Kolmogorov-Smirnov test is a quintessential univariate method.
- Univariate Drift: Methods like the KS test, PSI, and two-sample t-tests monitor changes in the marginal distribution of individual features. They are computationally efficient and easy to interpret but can miss complex interactions.
- Multivariate Drift: Methods like JSD, Maximum Mean Discrepancy (MMD), and classifier-based detectors analyze the joint distribution of all features or a subset. They can detect subtle, correlated shifts but are more complex and computationally intensive.
- Practical Strategy: A robust monitoring system often employs both: univariate tests like KS for granular, feature-level alerts and multivariate tests for a holistic system health check.
Drift Threshold
A drift threshold is a predefined, configurable limit on a statistical drift score (e.g., the KS test's D-statistic or p-value) beyond which a significant data drift is declared, triggering alerts or automated actions.
- Setting Thresholds: For the KS test, a common threshold is a p-value < 0.05 (or a Bonferroni-corrected value for multiple tests) to reject the null hypothesis of identical distributions. The D-statistic magnitude can also be used (e.g., D > 0.1).
- Operational Role: Thresholds translate statistical results into business logic. Exceeding a threshold might trigger a dashboard alert, an incident ticket, or an automated retraining trigger.
- Dynamic Adjustment: In production, thresholds may be tuned based on the cost of false alarms versus missed detections, and may adapt to seasonal patterns in the data.
Reference Dataset
A reference dataset is the baseline or benchmark data—typically the data used to train a model or a trusted historical snapshot—against which incoming production data is statistically compared using tests like the KS test to detect drift.
- Selection Criteria: The reference set should be representative of the stable, desired data state. It is often the training set, a validation set, or a specific golden snapshot from a period of known good model performance.
- Role in KS Test: In the two-sample KS test, the empirical cumulative distribution function (ECDF) of the production dataset is compared to the ECDF of the reference dataset. The test's validity depends on the reference set being a reliable baseline.
- Maintenance: Reference datasets may need periodic updating via manual review or automated processes to prevent them from becoming stale and causing false positive drift alerts.

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us