kfold_data: Get the data associated with a fold

Description Usage Arguments Value See Also Examples

View source: R/kfold.R

Description

kfold_data returns rows from data for a specific species for the kth fold. The get data from pre-made folds use get_fold_data

Usage

1
kfold_data(species_name, data, folds, fold, training)

Arguments

species_name

Character vector. The name of the species you want get the fold data for.

data

Dataframe. The occurrence or background data you want to get the fold data for.

folds

Dataframe. The occurrence or background folds as created by kfold_species_background. Essentially a data.frame with a species column and the k-fold cross-validation logical vectors.

fold

Integer. Indicate which kth fold you want to return data for.

training

Logical. If TRUE then training data is returned else if FALSE then test data is returned.

Value

Filtered version of data.

See Also

lapply_kfold_species, get_fold_data

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
## random data folds
set.seed(42)
occ_data <- data.frame(species = rep("Abalistes stellatus", 50),
                       longitude = runif(50, -180, 180), latitude = runif(50, -90, 90))
bg_data <- data.frame(species = rep("background", 1000),
                      longitude = runif(1000, -180, 180), latitude = runif(1000, -90, 90))
folds <- kfold_occurrence_background(occ_data, bg_data)
## alternative with real data (but see also the function get_fold_data)
# occ_data <- get_occurrences("Abalistes stellatus")
# bg_data <- load_background("random")
# folds <- load_folds("random")

## get training and test data for the first fold
occ_training <- kfold_data("Abalistes stellatus", occ_data, folds$occurrence,
                           fold = 1, training = TRUE)
occ_test <- kfold_data("Abalistes stellatus", occ_data, folds$occurrence,
                       fold = 1, training = FALSE)

bg_training <- kfold_data("Abalistes stellatus", bg_data, folds$background,
                          fold = 1, training = TRUE)
bg_test <- kfold_data("Abalistes stellatus", bg_data, folds$background,
                      fold = 1, training = FALSE)

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