Teradata R Package Function Reference | 17.00 - 17.00 - KNNRecommenderPredict - Teradata R Package

Teradata® R Package Function Reference

prodname
Teradata R Package
vrm_release
17.00
created_date
September 2020
category
Programming Reference
featnum
B700-4007-090K

Description

The KNNRecommenderPredict function applies the model output by the KNNRecommender Train function to predict the ratings or preferences that users would assign to entities like books, songs, movies and other products.

Usage

  td_knn_recommender_predict_mle (
      object = NULL,
      ratings.data = NULL,
      weights.data = NULL,
      bias.data = NULL,
      userid.column = NULL,
      itemid.column = NULL,
      rating.column = NULL,
      topk = 3,
      ratings.data.sequence.column = NULL,
      weights.data.sequence.column = NULL,
      bias.data.sequence.column = NULL,
      ratings.data.partition.column = NULL,
      ratings.data.order.column = NULL,
      weights.data.order.column = NULL,
      bias.data.order.column = NULL,
      showall = TRUE
  )
  
  ## S3 method for class 'td_knn_recommender_mle'
predict(
      object = NULL,
      ratings.data = NULL,
      weights.data = NULL,
      bias.data = NULL,
      userid.column = NULL,
      itemid.column = NULL,
      rating.column = NULL,
      topk = 3,
      ratings.data.sequence.column = NULL,
      weights.data.sequence.column = NULL,
      bias.data.sequence.column = NULL,
      ratings.data.partition.column = NULL,
      ratings.data.order.column = NULL,
      weights.data.order.column = NULL,
      bias.data.order.column = NULL,
      showall = TRUE
  )

Arguments

object

Specifies the name of the object returned by the KNNRecommenderTrain td_knn_recommender_mle function. For td_knn_recommender_predict_mle function, this is an optional argument, if both the arguments "weights.data" and "bias.data" are specified. For S3 predict function, this is a required argument. Whenever the argument "object" is specified, the arguments "weights.data" and "bias.data" will be overwritten by their equivalent objects of class "tbl_teradata" within "object" argument.

ratings.data

Required Argument.
Specifies the user rating tbl_teradata on which the predictions are to be made.

ratings.data.partition.column

Required Argument.
Specifies Partition By columns for "ratings.data".
Values to this argument can be provided as a vector, if multiple columns are used for partition.
Types: character OR vector of Strings (character)

ratings.data.order.column

Optional Argument.
Specifies Order By columns for "ratings.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)

weights.data

optional argument.
Specifies the tbl_teradata generated by td_knn_recommender_mle containing the interpolation weights. For S3 predict function, this argument is not required. For KNNRecommenderPredict function function, this is an optional argument. For KNNRecommenderPredict function function, if this argument is not specified, argument "object" must be specified. Whenever the argument "object" is specified, arguments "weights.data" and "bias.data" will be overwritten by their equivalent tibbles within "object" argument.

weights.data.order.column

Optional Argument.
Specifies Order By columns for "weights.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)

bias.data

Optional Argument.
Specifies the tbl_teradata generated by td_knn_recommender_mle containing the global, user, and item bias statistics. For S3 predict function, this argument is not required. For td_knn_recommender_predict_mle function, this is an optional argument. For td_knn_recommender_predict_mle function, if this argument is not specified, argument "object" must be specified. Whenever the argument "object" is specified, the arguments "weights.data" and "bias.data" will be overwritten by their equivalent tibbles within "object" argument.

bias.data.order.column

Optional Argument.
Specifies Order By columns for "bias.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)

userid.column

Optional Argument.
Specifies the user id column in the rating tbl_teradata. The default is the first column in the rating tbl_teradata.
Types: character

itemid.column

Optional Argument.
Specifies the item id column in the rating tbl_teradata. The default is the second column in the rating tbl_teradata.
Types: character

rating.column

Optional Argument.
Specifies the rating column in the rating tbl_teradata. The default is the third column in the rating tbl_teradata.
Types: character

topk

Optional Argument.
Specifies the number of items to recommend for each user. The "topk" highest-rated items are recommended.
Default Value: 3
Types: integer

showall

Optional Argument.
Specifies whether the function outputs only the "topk" values or all the values in case many recommendations have the same predicted rating.
When set to TRUE, and multiple items have the same predicted rating, the function outputs all these items, regardless of the value of "topk". Otherwise, the function outputs at most "topk" items.
Note: "showall" argument support is only available when tdplyr is connected to Vantage 1.1.1 or later.
Default Value: TRUE
Types: logical

ratings.data.sequence.column

Optional Argument.
Specifies the vector of column(s) that uniquely identifies each row of the input argument "ratings.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)

weights.data.sequence.column

Optional Argument.
Specifies the vector of column(s) that uniquely identifies each row of the input argument "weights.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)

bias.data.sequence.column

Optional Argument.
Specifies the vector of column(s) that uniquely identifies each row of the input argument "bias.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_knn_recommender_predict_mle" which is a named list containing object of class "tbl_teradata".
Named list member can be referenced directly with the "$" operator using the name: result.

Examples

    # Get the current context/connection
    con <- td_get_context()$connection
    
    # Load example data.
    loadExampleData("knnrecommender_example", "ml_ratings")
    loadExampleData("knnrecommenderpredict_example", "ml_ratings_10")
    
    # The ml_ratings table has movie ratings from 50 users.
    ml_ratings <- tbl(con, "ml_ratings")
    
    #  Build/generate the KNN Recommender model on the user ratings data
    td_knn_recommender_out <- td_knn_recommender_mle(rating.table = ml_ratings,
                                                 userid.column = "userid",
                                                 itemid.column = "itemid",
                                                 rating.column = "rating"
                                                )
                                          
    # ml_ratings_10 table has movie ratings from a subset of users from the ml_ratings 
    # table. The ml_bias and ml_weights table has the weights and bias values 
    # from the trained KNN Recommender model.
    ml_ratings_10 <- tbl(con, "ml_ratings_10")
    ml_weights <- td_knn_recommender_out$weight.model.table
    ml_bias <- td_knn_recommender_out$bias.model.table
                                               
    # Here "bias.data" and "weights.data" have been made optional with the argument "object"
    # having the td_knn_recommender_mle output object
    td_knn_recommender_predict_out <- td_knn_recommender_predict_mle(
                                                object = td_knn_recommender_out,
                                                ratings.data = ml_ratings_10,
                                                ratings.data.partition.column = c("userid"),
                                                topk = 5
                                               )
    
    # Alternatively use the S3 predict function to make user predictions. 
    td_knn_recommender_predict_out1 <- predict(object = td_knn_recommender_out,
                                                ratings.data = ml_ratings_10,
                                                ratings.data.partition.column = c("userid"),
                                                topk = 5
                                               )
                                               
    # Use the generated model to make user rating predictions. Here the argument "object"
    # has been made optional with the specification of both the arguments "bias.data" and
    # "weights.data"
    td_knn_recommender_predict_out2 <- td_knn_recommender_predict_mle(
                                                ratings.data = ml_ratings_10,
                                                ratings.data.partition.column = c("userid"),
                                                weights.data = ml_weights,
                                                bias.data = ml_bias,
                                                topk = 5
                                               )