feature_standardizer: Feature-wise standardization

Description Usage Arguments Value Class Methods Details Examples

Description

Standardize each feature of data. Three methodologies are supported:

Usage

1
feature_standardizer(method = 'l2', tol = sqrt(.Machine$double.eps)

Arguments

method

either "l2", "l1" or "range"

tol

positive real number, scaling is not conducted if scale is below this level

Value

FeatureStandardizer class object

Class Methods

fit(x, y = NULL)

fit to x and store the center and scale values

transform(x, y = NULL)

returns standardized x matrix

inv_transform(x, y = NULL)

returns pre-standardized x matrix

incr_fit(x, y = NULL)

currently not implemented

Details

When fitted to data, the feature-wise centers and scales are stored in the object, and transformation is conducted using these center and scale values. Therefore, when applied to new data, they are not exactly standardized.

Uses aad as the backend calculation for "l1" method

Examples

 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
32
33
34
35
36
37
38
39
40
41
42
43
data(mtcars)
# zero-mean, unit-variance standardization
fs <- feature_standardizer(method='l2')
fs$fit(mtcars)
z <- fs$transform(mtcars)$x
apply(z, MARGIN=2, FUN=mean)
apply(z, MARGIN=2, FUN=sd)
w <- fs$inv_transform(z)$x
range(mtcars-w)

# zero-mean, unit-MAD (mean absolute deviation)
fs <- feature_standardizer(method='l1')
fs$fit(mtcars)
z <- fs$transform(mtcars)$x
apply(z, MARGIN=2, FUN=mean)
apply(z, MARGIN=2, FUN=lsr::aad)
w <- fs$inv_transform(z)$x
range(mtcars-w)

# standardize to unit interval
fs$set_parameters(method='range')
fs$fit(mtcars)
z <- fs$transform(mtcars)$x
apply(z, MARGIN=2, FUN=range)
w <- fs$inv_transform(z)$x
range(mtcars-w)

# incremental fit is allowed for l2 and range method
fs$set_parameters(method='l2')
fs$fit(mtcars)
fs2 <- feature_standardizer(method='l2')
fs2$incr_fit(mtcars[1:10,])
fs2$incr_fit(mtcars[11:32,])
cbind(fs$centers, fs2$centers)
cbind(fs$scales, fs2$scales)

fs$set_parameters(method='range')
fs$fit(mtcars)
fs2$set_parameters(method='range')
fs2$incr_fit(mtcars[1:14,])
fs2$incr_fit(mtcars[15:32,])
cbind(fs$centers, fs2$centers)
cbind(fs$scales, fs2$scales)

kota7/MLPipe documentation built on May 5, 2019, 5:53 p.m.