Splits a dataset into a left half and a right half (e.g. train / test).
Source:R/dataset-utils.R
split_dataset.RdSplits a dataset into a left half and a right half (e.g. train / test).
Usage
split_dataset(
dataset,
left_size = NULL,
right_size = NULL,
shuffle = FALSE,
seed = NULL,
preferred_backend = NULL
)Arguments
- dataset
A
tf$data$Dataset, atorch$utils$data$Datasetobject, or a list of arrays with the same length.- left_size
If float (in the range
[0, 1]), it signifies the fraction of the data to pack in the left dataset. If integer, it signifies the number of samples to pack in the left dataset. IfNULL, defaults to the complement toright_size. Defaults toNULL.- right_size
If float (in the range
[0, 1]), it signifies the fraction of the data to pack in the right dataset. If integer, it signifies the number of samples to pack in the right dataset. IfNULL, defaults to the complement toleft_size. Defaults toNULL.- shuffle
Boolean, whether to shuffle the data before splitting it.
- seed
A random seed for shuffling.
- preferred_backend
Optional string specifying which backend to use, such as
"tensorflow"or"torch". IfNULL, the backend is inferred fromdataset: TensorFlow is used for atf.data.Dataset, Torch is used for atorch.utils.data.Dataset, and the current Keras backend is used for an R list or array. Defaults toNULL.
Value
A list of two dataset objects, the left and right splits. The exact type
depends on preferred_backend and on the input dataset type. For example,
the TensorFlow backend returns tf.data.Dataset objects and the Torch
backend returns torch.utils.data.Dataset objects.
Examples
data <- random_uniform(c(1000, 4))
c(left_ds, right_ds) %<-% split_dataset(list(data$numpy()), left_size = 0.8)
left_ds$cardinality()right_ds$cardinality()See also
Other dataset utils: audio_dataset_from_directory() image_dataset_from_directory() text_dataset_from_directory() timeseries_dataset_from_array()
Other utils: audio_dataset_from_directory() clear_session() config_disable_interactive_logging() config_disable_traceback_filtering() config_enable_interactive_logging() config_enable_traceback_filtering() config_is_interactive_logging_enabled() config_is_traceback_filtering_enabled() get_file() get_source_inputs() image_array_save() image_dataset_from_directory() image_from_array() image_load() image_smart_resize() image_to_array() layer_feature_space() normalize() pad_sequences() set_random_seed() text_dataset_from_directory() timeseries_dataset_from_array() to_categorical() zip_lists()