| augment_data | R Documentation |
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").
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,
...
)
data |
Training data: a data frame, matrix or |
... |
Passed to |
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 |
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 |
seed |
Optional random seed. |
nsim |
For time series: number of synthetic series. |
A data frame (tabular data) or a list of ts objects (time series).
ts_windows(), fit_synthesizer()
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))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.