PSALSA Example 3: User Similarity and Product Recommendation - Teradata Vantage

Machine Learning Engine Analytic Function Reference

Product
Teradata Vantage
Release Number
8.00
1.0
Published
May 2019
Language
English (United States)
Last Update
2019-11-22
dita:mapPath
blj1506016597986.ditamap
dita:ditavalPath
blj1506016597986.ditaval
dita:id
B700-4003
lifecycle
previous
Product Category
Teradata Vantageā„¢

This example finds similar customers and recommended products for them.

Teradata recommends PSALSA for recommending products to similar users when the product line has limited pairwise history or changes frequently. An example of a product line that changes frequently is apparel, which is subject to seasons and trends.

Input

  • vertices: user_product_nodes, which has customer names
  • edges: women_apparel_log, which reflects customer shopping patterns
vertices:user_product_nodes
nodeid nodename
1 Sandra
2 Susan
3 Stacie
4 Stephanie
5 Sally
6 coats
7 sweaters
8 jackets
9 blazers
10 pants
11 pajamas
edges: women_apparel_log
username product frequency
Sally blazers 2
Sally coats 10
Sally jackets 8
Sally sweaters 9
Sandra coats 10
Sandra jackets 8
Sandra sweaters 9
Stacie pajamas 9
Stacie pants 9
Stephanie blazers 5
Stephanie jackets 4
Stephanie pajamas 7
Stephanie pants 6
Susan blazers 5
Susan jackets 2
Susan pajamas 5
Susan pants 4
Susan sweaters 4

SQL Call

This call outputs a maximum of two similar users (hub) and recommends two products (authority) for each user, using frequency of purchase as a weight factor.

SELECT * FROM PSALSA (
  ON user_product_nodes AS vertices PARTITION BY nodename
  ON women_apparel_log AS edges PARTITION BY username
  USING
  SourceKey ('username')
  TargetKey ('product')
  EdgeWeight ('frequency')
  MaxHubNum (2)
  MaxAuthorityNum (2)
  TeleportProb (0.15)
  RandomWalkLength (500)
) AS dt ORDER BY username, hub_score DESC, authority_score DESC;

Output

The output shows possible recommendations, based on hub_score and authority_score. For example, the seller can recommend pajamas to Sandra and Susan because they and Sally have similar scores. The hub_score and authority_score values vary with every run.

username hub_username hub_score authority_product authority_score
Sally     pajamas 0.126984126984127
Sally     pants 0.119047619047619
Sally Sandra 0.239043824701195    
Sally Susan 0.159362549800797    
Sandra     pants 0.111111111111111
Sandra     pajamas 0.107142857142857
Sandra Sally 0.270916334661355    
Sandra Susan 0.151394422310757    
Stacie     sweaters 0.107569721115538
Stacie     blazers 0.103585657370518
Stacie Stephanie 0.212    
Stacie Susan 0.164    
Stephanie     coats 0.119521912350598
Stephanie Susan 0.2    
Stephanie Stacie 0.184    
Susan     coats 0.146825396825397
Susan Stacie 0.183266932270916    
Susan Stephanie 0.175298804780877