augment_data: Augment a small training set with synthetic data

View source: R/augment.R

augment_dataR Documentation

Augment a small training set with synthetic data

Description

Fits a synthesizer to data and returns the real records together with synthetic ones, ready to train a machine-learning model.

  • For a data frame (or matrix), n synthetic rows are appended to the real rows. An indicator column can be added with label. A vector is extended with n synthetic values.

  • For a time series, nsim synthetic series of length n are drawn (see fit_synthesizer.ts()) and returned in a list, preceded by the real series. Use ts_windows() to turn the list into a table of lagged features.

Synthetic data cannot add information that is not in the real data. What they add is a smoothed version of the training distribution, which acts as a regulariser and mainly helps flexible, high-variance learners (trees, nearest neighbours, neural networks) trained on small samples. Always fit the synthesizer on the training data only and measure the effect on held-out real data; see vignette("augmentation").

Usage

augment_data(data, ...)

## S3 method for class 'data.frame'
augment_data(
  data,
  n = 10L * nrow(data),
  keep_real = TRUE,
  label = NULL,
  closeness = 1,
  perturb = NULL,
  seed = NULL,
  ...
)

## Default S3 method:
augment_data(data, ...)

## S3 method for class 'matrix'
augment_data(data, ...)

## S3 method for class 'ts'
augment_data(
  data,
  nsim = 20L,
  n = NROW(data),
  keep_real = TRUE,
  seed = NULL,
  ...
)

Arguments

data

Training data: a data frame, matrix or ts object.

...

Passed to fit_synthesizer() (e.g. by, copula, or for time series method, order).

n

For tabular data: number of synthetic rows (default: 10 times the training size). For time series: length of each synthetic series (default: the length of data).

keep_real

Include the real data in the result?

label

Optional name of a logical column marking synthetic rows (tabular data only).

closeness, perturb

How close the synthetic rows are to the real ones (tabular data only); see generate(). Lower closeness gives more diverse synthetic rows.

seed

Optional random seed.

nsim

For time series: number of synthetic series.

Value

A data frame (tabular data) or a list of ts objects (time series).

See Also

ts_windows(), fit_synthesizer()

Examples

train <- mtcars[1:20, ]
big <- augment_data(train, n = 500, label = "synthetic", seed = 1)
table(big$synthetic)

series <- augment_data(ldeaths, nsim = 5, order = 12, seed = 1)
length(series)
head(ts_windows(series, lags = 12))

SynthesizerPlus documentation built on Oct. 16, 2026, 5:10 p.m.