Description Usage Arguments Details Value Feature Rescaling Feature Standardization Feature Normalization Author(s) Examples
Scale features in a datasets.
1 2 3 4 5 6 7 8 9 10 11 | feature_rescale(x, x_min = NULL, x_max = NULL)
feature_derescale(x_rescaled, x_min, x_max)
feature_norm(x, x_norm = NULL)
feature_denorm(x_norm_std, x_norm = NULL)
feature_standardize(x, x_mean = NULL, x_sd = NULL)
feature_destandardize(x_std, x_mean = NULL, x_sd = NULL)
|
x |
Numeric values |
x_min |
Minimum non-normalized numeric value |
x_max |
Maximum non-normalized numeric value |
x_rescaled |
Rescaled values of |
x_norm |
Euclidean norm of x |
x_norm_std |
Euclidean vector of normalized |
x_mean |
Mean of |
x_sd |
Standard Deviation of |
x_std |
Z-transformed |
The following functions provide a means to either scale features or to descale the features and return them to normal. These functions are ideal for working with optimizers.
Feature Scale | Feature Descale |
feature_rescale | feature_derescale |
feature_norm | feature_denorm |
feature_standardize | feature_destandardize |
A numeric
vector.
Convert the original data x to x_{scaled}:
x_{scaled} = \frac{(x-x_{min})}{(x_{max}-x_{min})}
To move from the rescaled value x_{scaled} to the original value x use:
x = x_{scaled} * (x_{max} - x_{min}) + x_{min}
Convert the original data x to x_{std}:
x_{std} = \frac{(x-\bar{x})}{σ_{x}}
To move from the standardized value x_{std} to the original value x use:
x = x_{std} σ_{x} + \bar{x}
Convert the original data x to x_{norm}:
x_{norm} = \frac{x}{≤ft\| x \right\|}
To move from the normalized value x_{norm} to the original value x use:
x = x_{norm} ≤ft\| x \right\|
James Balamuta
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | # Rescaling Features
temperatures = c(94.2, 88.1, 32, 0)
temp_min = min(temperatures)
temp_max = max(temperatures)
temperatures_norm = feature_rescale(temp_min, temp_max)
temperatures_denorm = feature_derescale(temperatures_norm, temp_min, temp_max)
all.equal(temperatures, temperatures_denorm)
# Norming Features
x = 1:10
x_norm = sqrt(sum(x^2))
x_norm_std = feature_norm(x, x_norm)
x_recover = feature_denorm(x_norm_std, x_norm)
all.equal(x, x_recover)
# Standardizing Features
x = 1:10
x_mean = mean(x)
x_sd = sd(x)
x_std = feature_standardize(x, x_mean, x_sd)
x_recovery = feature_destandardize(x, x_mean, x_sd)
all.equal(x, x_recovery)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.