spatialcvR provides tools for spatial cross-validation and model evaluation for geospatial machine learning applications. It addresses the fundamental problem that geographic observations are often not independent, which can lead to over-optimistic performance estimates when using standard random cross-validation.
In geospatial data analysis, nearby observations tend to be similar (Tobler's First Law of Geography). When using traditional random cross-validation, training and test sets may contain observations that are spatially close, leading to:
spatialcvR implements spatial cross-validation methods that explicitly control the separation between training and test observations:
# Install from CRAN (when available)
install.packages("spatialcvR")
# Install development version from GitHub
# devtools::install_github("yourusername/spatialcvR")
library(spatialcvR)
# Load sample data
data(sample_spatial_data)
# Create spatial folds
folds <- spatial_folds(
data = sample_spatial_data,
x = "longitude",
y = "latitude",
k = 5,
method = "block"
)
# Detect spatial leakage
leakage <- detect_spatial_leakage(
data = sample_spatial_data,
folds = folds,
x = "longitude",
y = "latitude"
)
# Evaluate model performance
metrics <- spatial_metrics(
observed = test_values,
predicted = predictions
)
Perfect for researchers and practitioners working with:
This package is currently in development (version 0.1.0). The core functionality is being implemented and tested.
Contributions are welcome! Please feel free to submit a Pull Request or open an issue for bugs, feature requests, or questions.
MIT License - see LICENSE file for details.
If you use spatialcvR in your research, please cite it:
@software{spatialcvR,
title = {spatialcvR: Spatial Cross-Validation for Machine Learning},
author = {Mamadou SOW},
year = {2026},
url = {https://github.com/sowsalim01/spatialcvR}
}
This package was developed to address the need for robust spatial validation methods in R's geospatial machine learning ecosystem.
For questions, issues, or suggestions, please open an issue on GitHub.