Teradata R Package Function Reference - SVMSparsePredict - Teradata R Package - Look here for syntax, methods and examples for the functions included in the Teradata R Package.

Teradata® R Package Function Reference

Product
Teradata R Package
Release Number
16.20
Published
February 2020
Language
English (United States)
Last Update
2020-02-28
dita:id
B700-4007
lifecycle
previous
Product Category
Teradata Vantage

Description

The SparseSVMPredictor (td_svm_sparse_predict_sqle) function takes the model generated by the function SparseSVMTrainer (td_svm_sparse_mle) and a set of test samples (in sparse format) and outputs a prediction for each sample.

Usage

  td_svm_sparse_predict_sqle (
      object = NULL,
      newdata = NULL,
      sample.id.column = NULL,
      attribute.column = NULL,
      value.column = NULL,
      accumulate.label = NULL,
      output.class.num = 1,
      newdata.partition.column = NULL)
      
## S3 method for class 'td_svm_sparse_mle'
predict(
      object = NULL, 
      newdata = NULL,
      sample.id.column = NULL, 
      attribute.column = NULL, 
      value.column = NULL,
      accumulate.label = NULL, 
      output.class.num = 1,
      newdata.partition.column = NULL)

Arguments

object

Required Argument.
Specifies model table object generated by SparseSVMTrainer (td_svm_sparse_mle). For td_svm_sparse_predict_sqle, this can also be the tibble containing the model table of sparse SVM model.

newdata

Required Argument.
Specifies the tbl_teradata containing the input test data.

newdata.partition.column

Partition By columns for newdata.
Values to this argument can be provided as a list, if multiple columns are used for ordering.

sample.id.column

Required Argument.
Specifies the name of the input tbl_teradata column that contains the identifiers of the test samples. The input tbl_teradata must be partitioned by this column.

attribute.column

Required Argument.
Specifies the name of the input tbl_teradata column that contains the attributes of the test samples.

value.column

Optional Argument.
Specifies the name of the input tbl_teradata column that contains the attribute values. By default, each attribute has the value 1.

accumulate.label

Optional Argument.
Specifies the names of the input tbl_teradata columns to copy to the output tbl_teradata.

output.class.num

Optional Argument.
Specifies the number of class labels to appear in the output tbl_teradata, with its corresponding prediction confidence.
Note: This argument is valid only for multiple-class models.
Default Value: 1

Value

Function returns an object of class "td_svm_sparse_predict_sqle" which is a named list containing Teradata tbl object. 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("svmsparsepredict_example", "svm_iris_input_test", "svm_iris_input_train")
    
    # Create remote tibble objects.
    svm_iris_input_train <- tbl(con, "svm_iris_input_train")
    svm_iris_input_test <- tbl(con, "svm_iris_input_test")
    
    # Example - 
    # Create the Sparse SVM model.
    svm_train <- td_svm_sparse_mle(data = svm_iris_input_train, 
                                   sample.id.column = 'id', 
                                   attribute.column = 'attribute', 
                                   value.column = 'value1', 
                                   label.column = 'species', 
                                   max.step = 150, 
                                   seed = 0
                                   )
    
    # Run predict on the output of td_svm_sparse_mle.
    svm_sparse_predict_result <- td_svm_sparse_predict_sqle(newdata = svm_iris_input_test,
                                                            newdata.partition.column = c("id"),
                                                            object = svm_train,
                                                            sample.id.column = "id",
                                                            attribute.column = "attribute",
                                                            value.column = "value1",
                                                            accumulate.label = c("species")
                                                            )
                                    
    # Alternatively use S3 predict on the output of td_svm_sparse_mle to find prediction.
    predict_out <- predict(svm_train,
                           newdata = svm_iris_input_test,
                           newdata.partition.column = c("id"),
                           sample.id.column = "id",
                           attribute.column = "attribute",
                           value.column = "value1",
                           accumulate.label = c("species")
                           )