Learn R Programming

marinespeed (version 0.1.0)

kfold_grid: Create k grid based folds for cross-validation

Description

kfold_grid creates a k-fold partitioning of geographical data for cross-validation based on spatial grid partitioning. Returns a vector with fold numbers ranging from 1 to k.

Usage

kfold_grid(data, k = 4, lonlat = TRUE)

Arguments

data
Matrix or dataframe. The first two columns should represent the longitude and latitude (or x,y coordinates if lonlat = FALSE).
k
Integer. The number of folds (partitions) that have to be created. This should be a square number (e.g 4, 9, 16). By default 4 folds are created.
lonlat
Logical. If TRUE (default) then the dateline is taken into account (see details) else if FALSE quantiles of x and y are used as splitting points

Value

A vector with fold numbers ranging from 1 to k.

Details

If lonlat = TRUE then the data is first split along the longitude based on a random starting point and then splitting in parts with k/2 points while crossing the dateline. Then each part is splitted along quantiles of the latitude in each part.

See Also

plot_folds, kfold_disc, kfold, , kfold_occurrence_background

Examples

Run this code
set.seed(42)
lonlat_data <- cbind(runif(11, -180, 180), runif(11, -90, 90))
folds <- kfold_grid(lonlat_data, k = 4)
plot_folds(lonlat_data, folds)

# for x,y data
xy_data <- cbind(runif(11, 0, 100), runif(11, 0, 100))
folds <- kfold_grid(xy_data, k = 4, lonlat = FALSE)
plot_folds(xy_data, folds)

Run the code above in your browser using DataLab