Description
The Scale function uses statistical information from the ScaleMap
(td_scale_map_mle
) function to scale the input data set.
Usage
td_scale_mle (
object = NULL,
data = NULL,
method = NULL,
global = FALSE,
accumulate = NULL,
multiplier = 1,
intercept = "0",
input.columns = NULL,
object.sequence.column = NULL,
data.sequence.column = NULL,
object.order.column = NULL,
data.order.column = NULL
)
Arguments
object |
Required Argument.
Specifies the statistical input generated by td_scale_map_mle
function.
|
object.order.column |
Optional Argument.
Specifies Order By columns for "object".
Values to this argument can be provided as a vector, if multiple
columns are used for ordering.
Types: character OR vector of Strings (character)
|
data |
Required Argument.
Specifies the input tbl_teradata for scaling.
|
data.order.column |
Optional Argument.
Specifies Order By columns for "data".
Values to this argument can be provided as a vector, if multiple
columns are used for ordering.
Types: character OR vector of Strings (character)
|
method |
Required Argument.
Specify one or more statistical methods used to scale the dataset.
If you specify multiple methods, the output tbl_teradata includes the column
scalemethod (which contains the method name) and a row for each
input-row/method combination.
Permitted Values: MEAN, SUM, USTD, STD, RANGE, MIDRANGE, MAXABS
Types: character OR vector of characters
|
global |
Optional Argument.
Specifies whether all input columns are scaled to the same location
and scale.
Note: Each input column is scaled separately.
Default Value: FALSE
Types: logical
|
accumulate |
Optional Argument.
Specifies the input tbl_teradata columns to copy to the output tbl_teradata.
By default, the function copies no input tbl_teradata columns to the
output tbl_teradata.
Types: character OR vector of Strings (character)
|
multiplier |
Optional Argument.
Specifies one or more multiplying factors to apply to the input
variables-multiplier in the following formula:
X' = intercept + multiplier * (X - location)/scale
If you specify only one multiplier, it applies to all columns
specified in the "input.columns" argument. If you specify multiple
multiplying factors, each multiplier applies to the corresponding
input column. For example, the first multiplier applies to the
first column specified in the "input.columns" argument, the second
multiplier applies to the second input column, and so on.
Default Value: 1
Types: numeric OR vector of numerics
|
intercept |
Optional Argument.
Specifies one or more addition factors incrementing the scaled
results-intercept in the following formula:
X' = intercept + multiplier * (X - location)/scale
If you specify only one intercept, it applies to all columns
specified in the "input.columns" argument. If you specify multiple
addition factors, each intercept applies to the corresponding input
column.
The syntax of intercept is: [-]{number | min | mean | max }
where min, mean, and max are the global minimum,
mean and maximum values in the corresponding columns.
The function scales the values of min, mean, and max. This is the
formula for computing the scaled global minimum:
scaledmin = (minX - location)/scale
The formulas for computing the scaled global mean and maximum are
analogous to the preceding formula.
For example, if intercept is "- min" and multiplier is 1, the scaled
result is transformed to a nonnegative sequence according to this formula,
where scaledmin is the scaled value:
X' = -scaledmin + 1 * (X - location)/scale.
Default Value: "0"
Types: character OR vector of characters
|
input.columns |
Optional Argument.
Specifies the input tbl_teradata columns that contain the attribute
values of the samples. The attribute values must be numeric values
between -1e308 and 1e308. If a value is outside this range, the
function treats it as infinity. The default input columns are all
columns of the statistic tbl_teradata (the output of the td_scale_map_mle
function) except stattype.
Types: character OR vector of Strings (character)
|
object.sequence.column |
Optional Argument.
Specifies the vector of column(s) that uniquely identifies each row
of the input argument "object". The argument is used to ensure
deterministic results for functions which produce results that vary
from run to run.
Types: character OR vector of Strings (character)
|
data.sequence.column |
Optional Argument.
Specifies the vector of column(s) that uniquely identifies each row
of the input argument "data". The argument is used to ensure
deterministic results for functions which produce results that vary
from run to run.
Types: character OR vector of Strings (character)
|
Value
Function returns an object of class "td_scale_mle" which is a named
list containing object of class "tbl_teradata".
Named list member can be referenced directly with the "$" operator
using name: result.
Examples
# Get the current context/connection
con <- td_get_context()$connection
# Load example data.
loadExampleData("scalemap_example", "scale_housing")
loadExampleData("scale_example", "scale_stat", "scale_housing_test")
# Create object(s) of class "tbl_teradata".
scale_housing <- tbl(con, "scale_housing")
scale_housing_test <- tbl(con, "scale_housing_test")
scale_stat <- tbl(con, "scale_stat")
# Example 1 - This example scales (normalizes) input data using the
# midrange method and the default values for the arguments "intercept"
# and "multiplier" (0 and 1 respectively).
td_scale_map_out <- td_scale_map_mle(data=scale_housing,
input.columns=c('price','lotsize','bedrooms',
'bathrms','stories')
)
td_scale_out1 <- td_scale_mle(object=td_scale_map_out,
data=scale_housing,
method=c("midrange"),
accumulate=c("id")
)
# Example 2 - This example uses a tbl_teradata as input for object argument and
# the "intercept" argument has the value "-min" (where min is the global minimum value)
# and we also specify different multiplier values for corresponding columns.
td_scale_out2 <- td_scale_mle(object = scale_stat,
data = scale_housing,
method = c("midrange"),
accumulate = c("id"),
multiplier = c(1,2,3,4,5),
intercept = c("-min")
)
# Example 3 - This example scales input data using multiple
# methods-midrange, mean, maxabs, and range.
td_scale_out3 <- td_scale_mle(object = scale_stat,
data = scale_housing_test,
method = c("midrange","mean","maxabs","range"),
accumulate = c("id")
)
# Example 4 - This example uses the Scale function to scale data (using
# the maxabs method) before inputting it to the function td_kmeans_mle(),
# which outputs the centroids of the clusters in the dataset.
loadExampleData("kmeans_example", "computers_train1")
computers_train1 <- tbl(con, "computers_train1")
td_scale_map_out4 <- td_scale_map_mle(data=computers_train1,
input.columns=c('price','speed','hd','ram'),
miss.value='OMIT'
)
# Create tbl_teradata of Scaled Data using Scale function.
td_scale_out4 <- td_scale_mle(object=td_scale_map_out4,
data=computers_train1,
method=c("maxabs"),
accumulate=c("id")
)
# Use the scaled data as input to KMeans to get clusters.
td_kmeans_out <- td_kmeans_mle(data = td_scale_out4$result,
centers = 8,
iter.max = 10,
threshold = 0.05
)