1.0 - 8.00 - KNNRecommenderPredict Example - Teradata Vantage

Teradata® Vantage Machine Learning Engine Analytic Function Reference

Product
Teradata Vantage
Release Number
1.0
8.00
Release Date
May 2019
Content Type
Programming Reference
Publication ID
B700-4003-098K
Language
English (United States)

Input

From the KNNRecommender Example:
  • ratings: ml_ratings
  • weights: ml_weights
  • bias: ml_bias

SQL Call

The call recommends five movies for ten users.

SELECT * FROM KnnRecommenderPredict (
  ON (SELECT * FROM ml_ratings WHERE userid <= 10) AS ratings
    PARTITION BY userid
  ON ml_bias AS bias DIMENSION
  ON ml_weights AS weights DIMENSION
  USING
  TopK (5)
) AS dt ORDER BY 1 DESC;

Output

userid itemid prediction
1 3703 5.11
1 2176 4.98
1 27773 4.94
1 1217 4.94
1 141 4.90
2 1269 4.86
2 2176 4.85
2 446 4.85
2 27773 4.77
2 3703 4.75
3 318 4.73
3 1217 4.65
3 2352 4.60
3 898 4.59
3 1247 4.58
4 3703 5.05
4 141 4.85
4 538 4.82
4 1240 4.81
4 858 4.79
5 44555 5.08
5 232 5.04
5 6664 4.99
5 76251 4.96
5 1516 4.92
6 2019 5.01
6 106487 4.94
6 951 4.92
6 141 4.86
6 3703 4.85
7 3703 4.99
7 318 4.94
7 141 4.93
7 1279 4.84
7 3702 4.76
8 1269 4.84
8 2183 4.64
8 1224 4.63
8 1883 4.61
8 1279 4.61
9 3703 4.83
9 8783 4.69
9 922 4.64
9 3504 4.57
9 7981 4.57
10 1269 4.45
10 3730 4.44
10 27773 4.43
10 1939 4.42
10 1136 4.39
Some predicted ratings are higher than 5, even though the maximum rating is 5. The weighted KNN recommendation algorithm does not limit its results to the range of the input data. The outcome of interest are the items with the highest recommendation score; if the resulting ratings must be limited to a specific range, normalize the output data.