Learn R Programming

marinespeed (version 0.1.0)

kfold_disc: Create k disc based folds for cross-validation

Description

kfold_disc creates a k-fold partitioning of geographical data for cross-validation based on the distance between points. The n points nearest to a selected point are put into a group. Returns a vector with fold numbers ranging from 1 to k.

Usage

kfold_disc(data, k = 5, 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. By default 5 folds are created.
lonlat
Logical. If TRUE (default) then Great Circle distances are calculated else if FALSE Euclidean (planar) distances are calculated.

Value

A vector with fold numbers ranging from 1 to k.

See Also

plot_folds, kfold_grid, kfold, kfold_occurrence_background

Examples

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

# use the euclidean distance
xy_data <- cbind(runif(11, 0, 100), runif(11, 0, 100))
folds <- kfold_disc(xy_data, k = 5, lonlat = FALSE)
plot_folds(xy_data, folds)

Run the code above in your browser using DataLab