To systematically quantify distributional discrepancies across datasets, a comprehensive drift and shift analysis was conducted. Given that the datasets under consideration originate from different environments and experimental setups, understanding the nature and magnitude of these discrepancies is critical for evaluating cross-dataset generalisation. To this end, the analysis was structured in two stages: First, a set of complementary statistical metrics were introduced to capture different aspects of distributional change. Subsequently, these metrics were applied across multiple dataset combinations to empirically examine feature-level drift and its implications for model robustness.
2.5.1. Drift–Shift Detection Metrics
To assess drift–shift between training and evaluation datasets in a systematic and interpretable manner, multiple complementary drift metrics were employed. Each metric captures a distinct aspect of distributional change, enabling a robust and multi-perspective analysis of feature-level stability across datasets.
Kolmogorov–Smirnov (KS) Test: The Kolmogorov–Smirnov test is a non-parametric statistical test that quantifies the maximum difference between the empirical cumulative distribution functions (ECDFs) of two samples. It directly measures structural changes in distribution shape without making assumptions about the underlying data distribution. The KS statistic is defined as follows:
where
and
denote the ECDFs of the training and test datasets, respectively. In this study, KS is primarily used as a fast and interpretable first-pass indicator of global distributional shift.
Kullback–Leibler Divergence: Kullback–Leibler (KL) divergence is asymmetric and particularly sensitive to rare events and unseen behaviours, making it suitable for identifying asymmetric or emergent distributional shifts. The KL divergence measures the information loss incurred when one probability distribution is used to approximate another. For discrete probability distributions, it is defined as follows:
Jensen–Shannon Divergence: Jensen–Shannon (JS) divergence is a symmetric and bounded variant of KL divergence that quantifies how much two distributions deviate from their shared mean distribution:
Since JS divergence is bounded in and numerically stable, it is well suited for comparative analyses across multiple features and datasets.
Wasserstein Distance: The Wasserstein distance (Earth Mover’s Distance) quantifies the geometric cost of transforming one distribution into another by comparing their quantile functions:
Unlike KS- or KL-based measures, Wasserstein distance explicitly captures shifts in mean, variance, and tail behaviour, making it particularly effective for continuous numerical features.
We employed a combination of KS, KL, JS, and Wasserstein metrics to capture different types of distributional shift. KS highlights structural shape changes, KL emphasises asymmetric and rare-event deviations, JS provides a stable similarity measure, and Wasserstein captures geometric displacement. Together, these metrics offer a comprehensive view of distributional changes across features.
Based on the characteristics and interpretability of these metrics, severity thresholds were defined to support consistent interpretation of distributional shifts.
Table 4 summarises the threshold ranges used to categorise drift severity levels across all metrics. Evaluating these metrics alongside the defined thresholds provides a unified framework for assessing feature-level stability and identifying features that require transformation, binning, or further preprocessing.
2.5.2. Drift–Shift Analysis Among the Datasets
Using the metrics described in
Section 2.5, distributional shift analysis was conducted for seven different experimental settings. These experimental groups can be summarised as follows:
BoT-IoT Train, ToN-IoT Test;
BoT-IoT Train, UNSW-NB15 Test;
ToN-IoT Train, BoT-IoT Test;
ToN-IoT Train, UNSW-NB15 Test;
BoT-UNSW Train, ToN-IoT Test;
ToN-UNSW Train, BoT-IoT Test;
BoT-ToN Train, UNSW-NB15 Test.
Given that the UNSW-NB15 dataset contains a substantially smaller number of samples compared to the other datasets, it was excluded from the individual training sets of the experiments to avoid potential bias and instability.
This section focuses on a representative scenario in which the training set is formed by the combination of the BoT-IoT and UNSW-NB15 datasets, while the ToN-IoT dataset is used as the test set. This scenario is representative of the analyses that can be performed for the remaining experimental configurations. Detailed tabular results and extended visual analyses for all dataset combinations are provided in the
Supplementary Materials (Section S2 and Section S3, respectively).
Table 5 shows the drift values obtained using different drift metrics.
Table 5 evaluates distributional deviations across multiple features using our four statistical metrics. The results indicate that, for nearly all features, substantial distributional shift is observed between the source and target datasets. This finding suggests that the data distribution on which the model is trained may no longer reflect the target environment and may negatively impact generalisation performance.
In particular, the MIN_IP_PKT_LEN_BIN feature shows drift, with KS (0.8084), KL (16.0188), and JS (0.3857) values indicating severe distributional divergence. Similarly, the SHORTEST_FLOW_PKT_BIN feature demonstrates significant information-theoretic drift, with a KL divergence of 27.9394 and a JS divergence of 0.4032. These features reflect substantial changes in packet-level traffic behaviour across datasets.
Traffic volume-related features such as OUT_BYTES_LOG and DST_TO_SRC_SECOND_BYTES _LOG also exhibit high drift levels, with KL values of 15.7417 and 9.0025 and JS values of 0.3607 and 0.3602, respectively. These results indicate pronounced differences in network load characteristics between the source and target domains. Moreover, binary-derived features such as OUT_BYTES_IS_ZERO (KL: 36.4804), IN_BYTES_LOG (KL: 26.6470), and FLOW_DURATION_IS_ZERO also indicate substantial drift, highlighting changes in fundamental traffic presence patterns.
Several features display particularly large deviations when evaluated using the Wasserstein distance. For example, SRC_TO_DST_AVG_THROUGHPUT yields near-zero KL and JS values, yet its Wasserstein distance reaches 258,202.4978, indicating major geometric shifts in feature values. Similarly, L4_SRC_PORT (15,579.8899) and L4_DST_PORT (5,567.6204) demonstrate substantial positional drift that is not readily captured by entropy-based metrics. These observations emphasise the necessity of incorporating geometric distance measures alongside distributional similarity metrics.
Protocol-, flag-, and duration-related features such as L7_PROTO, TCP_FLAGS, DURATION_ BIN, and NUM_PKTS_UP_TO_128_BYTES_LOG show moderate levels of drift (e.g., for L7_PROTO: KL = 1.1218, JS = 0.3127, Wasserstein = 41.8513). Although less extreme, these deviations indicate shifts in protocol usage patterns and session characteristics that may still influence model behaviour.
Only a limited number of features, such as DST_TO_SRC_SECOND_BYTES_HIGH_BURST and OUT_BYTES_HIGH_BURST, show relatively low drift values, suggesting a degree of stability. However, such features constitute exceptions rather than the norm across the feature space.
Overall, the analysis reveals the presence of widespread and multi-dimensional distributional shift across the examined datasets. Significant changes are observed not only in distributional shape (KS, JS) but also in value-level geometry (Wasserstein), while KL divergence highlights substantial information-theoretic discrepancies. These findings clearly indicate that a model trained on one dataset may fail to maintain reliable performance in target environments, posing a critical challenge for the deployment of a global-scale IoT-IDS.
2.5.3. Visual Representation of the Drift–Shift Among the Datasets
In order to better understand the magnitude and characteristics of distributional shift, we do not rely solely on numerical metrics but also leverage the power of visual analysis. For the constructed experimental setups, multiple graphical techniques are employed to analyse the differences between data distributions from complementary perspectives. Specifically, histogram plots, KDE, ECDF, and KDE difference plots are utilised. Each visualisation method is designed to highlight a different aspect of the distributional discrepancy.
Histogram plots provide a discretized approximation of the distribution of a continuous random variable by partitioning the data into bins. For a sample
, the histogram estimate for a bin
B can be defined as follows:
where
denotes the indicator function. Comparing histograms of training and test datasets allows for a direct inspection of shifts in shape, spread, and concentration regions. However, since histograms are sensitive to bin selection, a smoother representation is achieved through KDE.
KDE provides a non-parametric estimate of the underlying probability density function, yielding a continuous and smooth representation of the data distribution. It is defined as follows:
where
is the kernel function (commonly Gaussian) and
h is the bandwidth parameter. KDE enables a more refined comparison between training and test distributions, where the degree of overlap or separation between density curves directly reflects the severity of the drift.
The ECDF represents the cumulative probability of a variable and is defined as follows:
The ECDF is particularly effective for analysing differences in location and scale between distributions. The maximum deviation between two ECDFs is directly related to the Kolmogorov–Smirnov statistic:
Thus, ECDF plots provide a visual interpretation of statistical divergence between datasets.
KDE difference plots explicitly capture the discrepancy between two distributions at the density level. Given the estimated densities for training and test datasets, the difference is defined as follows:
This function highlights regions where one dataset exhibits higher density than the other. Specifically,
indicates regions dominated by the training data, whereas
corresponds to regions where the test data is more concentrated. Furthermore, the overall divergence between distributions can be quantified using the integral of the absolute difference:
which provides a global measure of distributional discrepancy.
These four visualisation techniques are jointly employed to provide a comprehensive analysis of drift–shift. Histograms reveal coarse structural differences, KDE captures smooth density variations, ECDF highlights cumulative behaviour, and KDE difference emphasizes localised deviations. This multi-perspective approach enables a deeper and more interpretable understanding of distributional shifts beyond purely numerical metrics.
In
Figure 3, where the model is trained on BoT-IoT and UNSW-NB15 and tested on ToN-IoT, the drift appears even more pronounced for several features.
Notably,
SRC_TO_DST_SECOND_BYTES_LOG and
DST_TO_SRC_SECOND_BYTES_LOG exhibit strong separation between training and test distributions, with minimal overlap, indicating a substantial change in traffic intensity patterns across datasets. Similarly,
NUM_PKTS_UP_TO_128_BYTES_LOG and
IN_BYTES_LOG demonstrate shifts toward higher values in the test set, suggesting that ToN-IoT contains systematically different packet-size and byte-volume characteristics [
60].
Packet-level features further reinforce this observation.
MIN_IP_PKT_LEN_BIN and
SHORTEST_FLOW_PKT_BIN show pronounced distributional shifts, where the training distribution is concentrated in lower bins while the test distribution extends toward higher bins, reflecting fundamentally different minimum packet-size behaviours between the two environments. This behaviour is consistent with packet-size distribution studies, which report that traffic tends to concentrate around small control segments while showing a second mode near the maximum transmission unit (MTU) boundary [
61,
62,
63]. Similarly,
TCP_WIN_MAX_IN_BIN reveals a shift in TCP window size patterns, pointing to protocol-level differences in device and connection behaviour.
Binary-derived features such as
OUT_BYTES_IS_ZERO and
FLOW_DURATION_IS_ZERO also demonstrate clear discrepancies in probability mass distribution, indicating that even fundamental traffic presence patterns differ across datasets. Protocol-level features including
L7_PROTO and
TCP_FLAGS exhibit shifts in dominant categories, further highlighting inconsistencies in application-layer behaviour, such as those arising from differences in protocol handshakes and session-establishment patterns [
64].
Port-based features such as L4_SRC_PORT and L4_DST_PORT also show clear discrepancies, where the training distributions tend to be more uniform while the test distribution introduces peaks in previously underrepresented regions, indicating differences in service usage and communication patterns. Furthermore, duration_bin exhibits a shift toward higher bins in the test set, implying longer flow durations in ToN-IoT compared to the training data.
In addition to histogram-based analysis, KDE plots provide a smoother and more continuous perspective on distributional differences, enabling a more precise examination of drift patterns.
Figure 4 presents the KDE-based analysis for the BoT+UNSW training and ToN-IoT test configuration, revealing distributional differences that extend beyond location shifts to fundamental changes in distributional shape.
DST_TO_SRC_SECOND_BYTES_LOG and SRC_TO_DST_SECOND_BYTES_LOG show near-complete separation between the training and test density curves, with negligible overlapping mass. This indicates that traffic intensity patterns in ToN-IoT are structurally incompatible with those observed during training, rather than merely shifted in location.
A qualitative change in modality is also evident. MIN_IP_PKT_LEN_BIN and SHORTEST_FLOW_PKT_BIN exhibit unimodal training distributions, whereas the corresponding test distributions are multimodal, suggesting that ToN-IoT captures multiple distinct packet-size regimes that are absent in the training data.
Conversely, MAX_IP_PKT_LEN_LOG and LONGEST_FLOW_PKT_LOG show the opposite pattern: bimodal training distributions that collapse into a single concentrated mode in the test set, implying reduced packet-size diversity in the test environment.
Binary features exhibit asymmetric variations in mass density. For the OUT_BYTES_IS_ZERO feature, the training distribution demonstrates a substantially higher concentration at value one compared to the test distribution. This indicates that flows with zero outgoing bytes are notably more frequent in the training environment, whereas the test environment contains a higher proportion of flows with active data transmission. A similar asymmetry appears in FLOW_DURATION_IS_ZERO, further suggesting that fundamental traffic presence patterns vary systematically across datasets.
Following the KDE-based analysis, ECDF plots provide a complementary and more statistically grounded perspective on distributional shift by capturing cumulative behaviour across the entire support. Unlike histogram and KDE representations, ECDF curves allow direct observation of distributional dominance, stochastic ordering, and maximum deviation between the training and test sets.
In
Figure 5, where the model is trained on BoT-IoT and UNSW-NB15 and tested on ToN-IoT, the ECDF curves show strong distributional shifts.
For SRC_TO_DST_SECOND_BYTES_LOG and DST_TO_SRC_SECOND_BYTES_LOG, the training ECDF consistently dominates the test ECDF across the entire support, with the test curve lagging substantially behind. This indicates that larger traffic intensity values are systematically more prevalent in the test domain, reflecting a clear stochastic ordering between datasets. A similar pattern appears in MIN_IP_PKT_LEN_BIN and SHORTEST_FLOW_PKT_BIN, where the training ECDF reaches its plateau at substantially lower values than the test ECDF, confirming that the test distribution is concentrated in higher bins.
In contrast, TCP_WIN_MAX_IN_BIN exhibits crossing ECDF curves, where neither distribution stochastically dominates the other. The training ECDF rises sharply at lower bin values, while the test ECDF surpasses it at higher bins, indicating a reversal in distributional ordering that cannot be characterised as a simple location shift.
Discrete binary features reveal differences in step structure rather than location. OUT_BYTES_IS_ZERO and FLOW_DURATION_IS_ZERO show substantially different jump heights at the same discrete values, with the training ECDF accumulating a larger probability mass at value zero than the test ECDF. This indicates that event frequencies for these binary indicators differ systematically across datasets. L4_DST_PORT further illustrates this asymmetry, with the training ECDF rising sharply near zero while the test ECDF increases gradually across the full port range, reflecting fundamentally different destination port usage patterns.
As a final step of the visual drift analysis, density difference plots provide a direct and localised quantification of distributional discrepancies by explicitly modelling the difference between training and test density functions.
Figure 6 shows the density difference analysis for the BoT+UNSW training and ToN-IoT test configuration. This representation directly quantifies the signed local discrepancy between distributions, identifying both the direction and the spatial extent of drift at each feature value.
Binary features show the largest absolute deviations. OUT_BYTES_IS_ZERO and FLOW_DURATION_IS_ZERO display sharp positive spikes at value zero and large negative spikes at value one, with peak discrepancies reaching approximately 25 units. This quantitative divergence indicates that the training distribution exhibits a predominant concentration at value zero, while the test distribution is more heavily weighted toward value one, revealing a systematic inversion of binary traffic states across datasets. A similar sign reversal appears in TCP_WIN_MAX_IN_BIN, where the positive deviation at lower bins and the negative deviation at higher bins directly corroborate the crossing ECDF pattern observed previously.
Packet-level features such as MIN_IP_PKT_LEN_BIN and SHORTEST_FLOW_PKT_BIN show clean sign transitions from positive to negative as the bin values increase, confirming that training data dominates at lower packet-size categories while the test distribution dominates at higher ones. In contrast, SRC_TO_DST_SECOND_BYTES_LOG and IN_BYTES_LOG exhibit oscillatory difference patterns with multiple sign changes, indicating that the distributional mismatch is not a simple directional shift but involves complex local density variations across the feature range.
Finally, OUT_BYTES_HIGH_BURST and DST_TO_SRC_SECOND_BYTES_HIGH_BURST show near-zero differences across most of their range, with sharp deviations only at boundary values, suggesting that drift for these features is highly localised rather than global. This pattern contrasts with the broader deviations observed in byte-volume and packet-size features, illustrating that distributional shift manifests differently depending on feature type and construction.
Across all four complementary visualisation techniques, a consistent and multi-dimensional picture of distributional shift emerges. Histogram analysis reveals shifts in the concentration regions and dominant value ranges of features, while KDE plots expose qualitative changes in distributional shape, including transitions between unimodal and multimodal structures. ECDF curves quantify cumulative ordering relationships and identify features where neither distribution stochastically dominates the other. Density difference plots further localise these discrepancies, distinguishing between global directional shifts, sign-reversing transitions, and boundary-concentrated deviations.
Critically, the observed drift is neither uniform nor restricted to a single feature category. Byte-volume features, packet-size indicators, binary traffic presence flags, TCP protocol attributes, and port-based features all exhibit distributional mismatches, albeit of different types and magnitudes. This heterogeneity implies that no single preprocessing transformation can fully resolve the cross-dataset inconsistency, and that distributional shift will manifest as a persistent challenge during model evaluation regardless of the feature engineering applied.
These findings directly motivate the experimental evaluation presented in the following section. If the feature distributions learned during training do not reflect those encountered at test time, the decision boundaries formed by machine learning models are expected to degrade in a predictable but dataset-dependent manner. The extent and nature of this degradation under different training configurations are explored in the following section.