| Title: | Leakage Detection for Environmental Sensor Data |
|---|---|
| Description: | Provides tools for identifying potential information leakage and validation risks in machine learning workflows using environmental sensor data. The package includes checks for temporal ordering, shared sensors, spatial proximity, and overlapping temporal windows. The diagnostics are motivated by considerations of spatial and temporal structure in model validation (Roberts et al., 2017) <doi:10.1111/ecog.02881>. |
| Authors: | Divya Umai Raja [aut, cre, cph], Sanjana Sujil [aut, cph] |
| Maintainer: | Divya Umai Raja <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.0 |
| Built: | 2026-09-30 14:12:42 UTC |
| Source: | https://github.com/cran/sensorLeak |
Identifies environmental sensors that occur in both training and testing observations. Shared sensors may represent a validation risk when the intended model should generalize to unseen sensors.
check_sensor_leakage(data, sensor, split)check_sensor_leakage(data, sensor, split)
data |
A data frame containing sensor observations. |
sensor |
A character string giving the column identifying the environmental sensor. |
split |
A character string giving the column identifying training and testing observations. |
A data frame containing sensors present in both splits, together with their observation counts.
data <- data.frame( sensor_id = c("S1", "S2", "S1", "S3"), split = c("train", "train", "test", "test") ) check_sensor_leakage( data, sensor = "sensor_id", split = "split" )data <- data.frame( sensor_id = c("S1", "S2", "S1", "S3"), split = c("train", "train", "test", "test") ) check_sensor_leakage( data, sensor = "sensor_id", split = "split" )
Identifies training and testing observations that are within a specified geographic distance of each other. Close observations may represent a validation risk when a model is intended to generalize to geographically independent locations.
check_spatial_leakage(data, lat, lon, split, threshold = 1)check_spatial_leakage(data, lat, lon, split, threshold = 1)
data |
A data frame containing geographic observations. |
lat |
A character string giving the latitude column. |
lon |
A character string giving the longitude column. |
split |
A character string giving the column identifying training and testing observations. |
threshold |
A numeric value giving the maximum distance in kilometres for observations to be considered spatially close. |
A data frame containing pairs of spatially close training and testing observations.
data <- data.frame( latitude = c(13.0827, 13.0830, 13.2000, 13.3000), longitude = c(80.2707, 80.2710, 80.3000, 80.4000), split = c("train", "test", "train", "test") ) check_spatial_leakage( data, lat = "latitude", lon = "longitude", split = "split", threshold = 1 )data <- data.frame( latitude = c(13.0827, 13.0830, 13.2000, 13.3000), longitude = c(80.2707, 80.2710, 80.3000, 80.4000), split = c("train", "test", "train", "test") ) check_spatial_leakage( data, lat = "latitude", lon = "longitude", split = "split", threshold = 1 )
Identifies test observations that occur before the end of the training period. Such observations may indicate an invalid temporal validation setup.
check_temporal_leakage(data, time, split)check_temporal_leakage(data, time, split)
data |
A data frame containing timestamped observations. |
time |
A character string giving the timestamp column. |
split |
A character string giving the column identifying training and testing observations. |
A data frame containing test observations that occur before the end of the training period.
data <- data.frame( timestamp = as.POSIXct( c( "2026-01-01 10:00:00", "2026-01-01 12:00:00", "2026-01-01 11:00:00", "2026-01-01 15:00:00" ) ), split = c("train", "train", "test", "test") ) check_temporal_leakage( data, time = "timestamp", split = "split" )data <- data.frame( timestamp = as.POSIXct( c( "2026-01-01 10:00:00", "2026-01-01 12:00:00", "2026-01-01 11:00:00", "2026-01-01 15:00:00" ) ), split = c("train", "train", "test", "test") ) check_temporal_leakage( data, time = "timestamp", split = "split" )
Detects temporal overlap between training and testing windows within environmental sensor data.
check_window_leakage(data, start, end, split, sensor)check_window_leakage(data, start, end, split, sensor)
data |
A data frame containing temporal windows. |
start |
A character string giving the column containing window start times. |
end |
A character string giving the column containing window end times. |
split |
A character string giving the column identifying training and testing observations. |
sensor |
A character string giving the column identifying the environmental sensor. |
A data frame containing detected overlapping windows.
data <- data.frame( sensor_id = c("S1", "S1"), window_start = as.POSIXct( c("2026-01-01 10:00:00", "2026-01-01 13:00:00") ), window_end = as.POSIXct( c("2026-01-01 14:00:00", "2026-01-01 18:00:00") ), split = c("train", "test") ) check_window_leakage( data, start = "window_start", end = "window_end", split = "split", sensor = "sensor_id" )data <- data.frame( sensor_id = c("S1", "S1"), window_start = as.POSIXct( c("2026-01-01 10:00:00", "2026-01-01 13:00:00") ), window_end = as.POSIXct( c("2026-01-01 14:00:00", "2026-01-01 18:00:00") ), split = c("train", "test") ) check_window_leakage( data, start = "window_start", end = "window_end", split = "split", sensor = "sensor_id" )
Prints a concise summary of the potential validation risks
identified by a sensor_audit object.
## S3 method for class 'sensor_audit' print(x, ...)## S3 method for class 'sensor_audit' print(x, ...)
x |
An object of class |
... |
Additional arguments passed to the method. |
Invisibly returns the audit object.
Print a sensor audit summary
## S3 method for class 'sensor_audit_summary' print(x, ...)## S3 method for class 'sensor_audit_summary' print(x, ...)
x |
An object of class |
... |
Additional arguments. |
Invisibly returns the summary object.
Runs multiple leakage checks on environmental sensor data and combines their findings into a single audit result.
sensor_audit(data, time, sensor, split, lat, lon, spatial_threshold = 1)sensor_audit(data, time, sensor, split, lat, lon, spatial_threshold = 1)
data |
A data frame containing environmental sensor data. |
time |
A character string giving the timestamp column. |
sensor |
A character string giving the sensor identifier column. |
split |
A character string giving the train/test split column. |
lat |
A character string giving the latitude column. |
lon |
A character string giving the longitude column. |
spatial_threshold |
A numeric value giving the spatial proximity threshold in kilometres. |
An object of class sensor_audit containing the
results of the leakage checks.
data <- data.frame( timestamp = as.POSIXct(c( "2026-01-01 10:00:00", "2026-01-01 12:00:00", "2026-01-01 14:00:00", "2026-01-01 16:00:00" )), sensor_id = c("S1", "S1", "S2", "S2"), latitude = c(13.08, 13.08, 13.20, 13.30), longitude = c(80.27, 80.27, 80.30, 80.40), split = c("train", "train", "test", "test") ) audit <- sensor_audit( data, time = "timestamp", sensor = "sensor_id", split = "split", lat = "latitude", lon = "longitude" )data <- data.frame( timestamp = as.POSIXct(c( "2026-01-01 10:00:00", "2026-01-01 12:00:00", "2026-01-01 14:00:00", "2026-01-01 16:00:00" )), sensor_id = c("S1", "S1", "S2", "S2"), latitude = c(13.08, 13.08, 13.20, 13.30), longitude = c(80.27, 80.27, 80.30, 80.40), split = c("train", "train", "test", "test") ) audit <- sensor_audit( data, time = "timestamp", sensor = "sensor_id", split = "split", lat = "latitude", lon = "longitude" )
A small synthetic dataset representing environmental sensor observations with timestamps, sensor identifiers, geographic coordinates, PM2.5 measurements, and train/test assignments.
sensor_datasensor_data
A data frame with 12 observations and 6 variables:
Timestamp of the sensor observation.
Identifier of the environmental sensor.
Latitude of the sensor location in decimal degrees.
Longitude of the sensor location in decimal degrees.
PM2.5 concentration measurement.
Training or testing assignment.
Synthetic example data created for the sensorLeak package.
data(sensor_data) head(sensor_data)data(sensor_data) head(sensor_data)
Provides detailed summary information for a sensor_audit
object.
## S3 method for class 'sensor_audit' summary(object, ...)## S3 method for class 'sensor_audit' summary(object, ...)
object |
An object of class |
... |
Additional arguments passed to the method. |
An object of class sensor_audit_summary.