OneClassSVMPredict
Description
The td_one_class_svm_predict_sqle()
function uses the model generated
by the function td_one_class_svm_sqle()
to predicts target class labels
(classification) on new input data. Output values are 0 and 1.
A value of 1 corresponds to a 'normal' observation, and a value
of 0 is assigned to 'outlier' observations.
Notes:
Standardize input features using
td_scale_fit_sqle()
andtd_scale_transform_sqle()
before using the function.The function takes only numeric features.
The categorical features must be converted to numeric values prior to prediction.
Rows with missing (null) values are skipped by the function during prediction.
For prediction results evaluation, user can use
td_classification_evaluator_sqle()
ortd_roc_sqle()
as the postprocessing step.
Usage
td_one_class_svm_predict_sqle (
object = NULL,
newdata = NULL,
id.column = NULL,
accumulate = NULL,
output.prob = FALSE,
output.responses = NULL,
...
)
Arguments
object |
Required Argument. |
newdata |
Required Argument. |
id.column |
Required Argument. |
accumulate |
Optional Argument. |
output.prob |
Optional Argument.
Default Value: FALSE |
output.responses |
Optional Argument.
Types: character OR vector of Strings (character) |
... |
Specifies the generic keyword arguments SQLE functions accept. Below
are the generic keyword arguments: volatile: Function allows the user to partition, hash, order or local order the input data. These generic arguments are available for each argument that accepts tbl_teradata as input and can be accessed as:
Note: |
Value
Function returns an object of class "td_one_class_svm_predict_sqle"
which is a named list containing object of class "tbl_teradata".
Named list member(s) can be referenced directly with the "$" operator
using the name(s):result
Examples
# Get the current context/connection.
con <- td_get_context()$connection
# Load the example data.
loadExampleData("tdplyr_example", "cal_housing_ex_raw")
# Create tbl_teradata object.
data_input <- tbl(con, "cal_housing_ex_raw")
# Check the list of available analytic functions.
display_analytic_functions()
# Scale "target_columns" with respect to 'STD' value of the column.
fit_obj <- td_scale_fit_sqle(
data=data_input,
target.columns=c('MedInc', 'HouseAge', 'AveRooms',
'AveBedrms', 'Population', 'AveOccup',
'Latitude', 'Longitude'),
scale.method="STD")
# Transform the data.
transform_obj <- td_scale_transform_sqle(
data=data_input,
object=fit_obj$output,
accumulate=c("id", "MedHouseVal"))
# Train the input data by td_one_class_svm_sqle() which helps model
# to find anomalies in transformed data.
one_class_svm <- td_one_class_svm_sqle(
data=transform_obj$result,
input.columns=c('MedInc', 'HouseAge', 'AveRooms',
'AveBedrms', 'Population', 'AveOccup',
'Latitude', 'Longitude'),
local.sgd.iterations=537,
batch.size=1,
learning.rate='constant',
initial.eta=0.01,
lambda1=0.1,
alpha=0.0,
momentum=0.0,
iter.max=1)
# Example 1 : Using trained data by td_one_class_svm_sqle model, predict whether observation
# is outlier or normal in the form of '0' or '1' on "newdata".
OneClassSVMPredict_out1 <- td_one_class_svm_predict_sqle(
object = one_class_svm$result,
newdata = transform_obj$result,
id.column = "id"
)
# Print the result.
print(OneClassSVMPredict_out1$result)
# Example 2 : Using trained data by td_one_class_svm_sqle model, predict whether observation
# is outlier or normal in the form of '0' or '1' also provides probability
# of outcome of '0' and '1' on "newdata".
OneClassSVMPredict_out2 <- td_one_class_svm_predict_sqle(
object = one_class_svm,
newdata = transform_obj$result,
id.column = "id",
accumulate="MedInc",
output.prob=TRUE,
output.responses=c("0", "1"))
# Print the result.
print(OneClassSVMPredict_out2$result)
# Alternatively use S3 predict function to run predict on the output of
# td_one_class_svm_sqle() function.
OneClassSVMPredict_out2 <- predict(
one_class_svm,
newdata = transform_obj$result,
id.column = "id",
accumulate="MedInc",
output.prob=TRUE,
output.responses=c("0", "1"))
# Print the result.
print(OneClassSVMPredict_out2$result)