data_transformer {RGAN} | R Documentation |
Data Transformer
Description
Provides a class to transform data for RGAN.
Method $new()
initializes a new transformer, method $fit(data)
learns
the parameters for the transformation from data (e.g. means and sds).
Methods $transform()
and $inverse_transform()
can be used to transform
and back transform a data set based on the learned parameters.
Currently, DataTransformer supports z-transformation (a.k.a. normalization)
for numerical features/variables and one hot encoding for categorical
features/variables. In your call to fit you just need to indicate which
columns contain discrete features.
Value
A class to transform (normalize or one hot encode) tabular data for RGAN
Methods
Public methods
Method new()
Create a new data_transformer object
Usage
data_transformer$new()
Method fit_continuous()
Usage
data_transformer$fit_continuous(column = NULL, data = NULL)
Method fit_discrete()
Usage
data_transformer$fit_discrete(column = NULL, data = NULL)
Method fit()
Fit a data_transformer to data.
Usage
data_transformer$fit(data, discrete_columns = NULL)
Arguments
data
The data set to transform
discrete_columns
Column ids for columns with discrete/nominal values to be one hot encoded.
Examples
data <- sample_toydata() transformer <- data_transformer$new() transformer$fit(data)
Method transform_continuous()
Usage
data_transformer$transform_continuous(column_meta, data)
Method transform_discrete()
Usage
data_transformer$transform_discrete(column_meta, data)
Method transform()
Transform data using a fitted data_transformer. (From original format to transformed format.)
Usage
data_transformer$transform(data)
Arguments
data
The data set to transform
Examples
data <- sample_toydata() transformer <- data_transformer$new() transformer$fit(data) transformed_data <- transformer$transform(data)
Method inverse_transform_continuous()
Usage
data_transformer$inverse_transform_continuous(meta, data)
Method inverse_transform_discrete()
Usage
data_transformer$inverse_transform_discrete(meta, data)
Method inverse_transform()
Inverse Transform data using a fitted data_transformer. (From transformed format to original format.)
Usage
data_transformer$inverse_transform(data)
Arguments
data
The data set to transform
Examples
data <- sample_toydata() transformer <- data_transformer$new() transformer$fit(data) transformed_data <- transformer$transform(data) reconstructed_data <- transformer$inverse_transform(transformed_data)
Method clone()
The objects of this class are cloneable with this method.
Usage
data_transformer$clone(deep = FALSE)
Arguments
deep
Whether to make a deep clone.
Examples
## Not run:
# Before running the first time the torch backend needs to be installed
torch::install_torch()
# Load data
data <- sample_toydata()
# Build new transformer
transformer <- data_transformer$new()
# Fit transformer to data
transformer$fit(data)
# Transform data and store as new object
transformed_data <- transformer$transform(data)
# Train the default GAN
trained_gan <- gan_trainer(transformed_data)
# Sample synthetic data from the trained GAN
synthetic_data <- sample_synthetic_data(trained_gan, transformer)
# Plot the results
GAN_update_plot(data = data,
synth_data = synthetic_data,
main = "Real and Synthetic Data after Training")
## End(Not run)
## ------------------------------------------------
## Method `data_transformer$fit`
## ------------------------------------------------
data <- sample_toydata()
transformer <- data_transformer$new()
transformer$fit(data)
## ------------------------------------------------
## Method `data_transformer$transform`
## ------------------------------------------------
data <- sample_toydata()
transformer <- data_transformer$new()
transformer$fit(data)
transformed_data <- transformer$transform(data)
## ------------------------------------------------
## Method `data_transformer$inverse_transform`
## ------------------------------------------------
data <- sample_toydata()
transformer <- data_transformer$new()
transformer$fit(data)
transformed_data <- transformer$transform(data)
reconstructed_data <- transformer$inverse_transform(transformed_data)