spatialcvR: Spatial Cross-Validation for Machine Learning

Overview

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.

The Problem

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:

The Solution

spatialcvR implements spatial cross-validation methods that explicitly control the separation between training and test observations:

Installation

# Install from CRAN (when available)
install.packages("spatialcvR")

# Install development version from GitHub
# devtools::install_github("yourusername/spatialcvR")

Quick Start

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
)

Key Features

Use Cases

Perfect for researchers and practitioners working with:

Documentation

Project Status

This package is currently in development (version 0.1.0). The core functionality is being implemented and tested.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request or open an issue for bugs, feature requests, or questions.

License

MIT License - see LICENSE file for details.

Citation

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}
}

Acknowledgments

This package was developed to address the need for robust spatial validation methods in R's geospatial machine learning ecosystem.

Contact

For questions, issues, or suggestions, please open an issue on GitHub.