Teradata R Package Function Reference - 16.20 - KNNRecommender - Teradata R Package

Teradata® R Package Function Reference

prodname
Teradata R Package
vrm_release
16.20
created_date
February 2020
category
Programming Reference
featnum
B700-4007-098K

Description

The KNNRecommender function trains a interpolation weight model based on weighted collaborative filtering approach. It uses the input user ratings data to create three model tables: the weights model table, the bias model table and the optional nearest items or neighbors table. These tables are then used to predict the ratings or preferences that users assign to entities like books, songs, movies, and other products.

Usage

  td_knn_recommender_mle (
      rating.table = NULL,
      userid.column = NULL,
      itemid.column = NULL,
      rating.column = NULL,
      k = 20,
      learning.rate = 0.001,
      max.iternum = 10,
      threshold = 2.0E-4,
      item.similarity = "Pearson",
      rating.table.sequence.column = NULL
  )

Arguments

rating.table

Required Argument.
Specifies the tbl_teradata containing the user ratings.

userid.column

Optional Argument.
Specifies the user id column in the argument "rating.table". The default is the first column in the rating table.

itemid.column

Optional Argument.
Specifies the item id column in the argument "rating.table". The default is the second column in the rating table.

rating.column

Optional Argument.
Specifies the rating column in the argument "rating.table". The default is the third column in the rating table.

k

Optional Argument.
Specifies the number of nearest neighbors used in the calculation of the interpolation weights.
Default Value: 20

learning.rate

Optional Argument.
Specifies the initial learning rate. The learning rate adjusts automatically during training based on changes in the RMSE.
Default Value: 0.001

max.iternum

Optional Argument.
Specifies the maximum number of iterations.
Default Value: 10

threshold

Optional Argument.
The function stops when the RMSE drops below this level.
Default Value: 2.0E-4

item.similarity

Optional Argument.
Specifies the method used to calculate item similarity.
Default Value: "Pearson"
Permitted Values: AdjustedCosine, Pearson

rating.table.sequence.column

Optional Argument.
Specifies the vector of column(s) that uniquely identifies each row of the input argument "rating.table". The argument is used to ensure deterministic results for functions which produce results that vary from run to run.

Value

Function returns an object of class "td_knn_recommender_mle" which is a named list containing Teradata tbl objects.
Named list members can be referenced directly with the "$" operator using following names:

  1. weight.model.table

  2. bias.model.table

  3. nearest.items

  4. output

Examples

    # Get the current context/connection
    con <- td_get_context()$connection
    
    # Load example data.
    loadExampleData("knnrecommender_example", "ml_ratings")
    
    # The ml_ratings table has movie ratings from 50 users on 
    # approximately 2900 movies, with an average of about 150 ratings 
    # for each user. The 10 possible ratings range from 0.5 to 5
    # in steps of 0.5. A higher number indicates a better rating.
    ml_ratings <- tbl(con, "ml_ratings")
    
    # Example 1 - Train the KNN Recommender system 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"
                                                 )