kfold_grid: Create k grid based folds for cross-validation

Description Usage Arguments Details Value See Also Examples

View source: R/kfold.R

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

1
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

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.

Value

A vector with fold numbers ranging from 1 to k.

See Also

plot_folds, kfold_disc, kfold, , kfold_occurrence_background

Examples

1
2
3
4
5
6
7
8
9
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)

lifewatch/marinespeed documentation built on Dec. 19, 2019, 2:59 a.m.