standardize: Standardize training data and test data

Description Usage Arguments Details Value Examples

View source: R/standardize.R

Description

Standardize training and test data by the information of training data. Test data is standardized using the information of training data.

Usage

1
standardize(test, train, y_method = c("center", "scale"))

Arguments

test

Test data to standardize.

train

Training data that is standardized and used to standardize test data.

y_method

Decide how outcome will be standardized. If FALSE, nothing is applied.

Details

Standardization will be done by following formula: z = (x - mean(x)) / sd(x)

Value

A list that has standardized training and test data, which includes standard deviation and mean of outcome, The outcome of test data is not changed.

train

Standardized training data

test

Standardized test data

y_mean

A value used for centering (mean of outcome in training data)

y_sd

A value used for scaling (standard deviation of outcome in test data)

Examples

1
2
3
4
5
6
data_train <- data.frame(y = rnorm(10), x1 = rnorm(10), x2 = rnorm(10))
data_test <- data.frame(y = rnorm(10), x1 = rnorm(10), x2 = rnorm(10))
apply(data_train, 2, mean); apply(data_train, 2, sd)
data_scaled <- standardize(test = data_test,
train = data_train, y_method = "scale")
apply(data_scaled$train, 2, mean); apply(data_scaled$train, 2, sd)

SwanCygnus/predata documentation built on July 1, 2020, 12:09 a.m.