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

Teradata® Package for R Function Reference

Product
Teradata Package for R
Release Number
17.00
Published
July 2021
Language
English (United States)
Last Update
2023-08-08
dita:id
B700-4007
NMT
no
Product Category
Teradata Vantage
KNNRecommenderTrain

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".
Types: character

itemid.column

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

rating.column

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

k

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

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
Types: numeric

max.iternum

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

threshold

Optional Argument.
Specifies the function stops when the RMSE drops below this level.
Default Value: 0.0002.
Types: numeric

item.similarity

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

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.
Types: character OR vector of Strings (character)

Value

Function returns an object of class "td_knn_recommender_mle" which is a named list containing objects of class "tbl_teradata".
Named list members can be referenced directly with the "$" operator using the 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"
                                                 )