Created
April 26, 2021 02:15
-
-
Save eugeneyan/6a58c7ce58ef1a69eb8edfc083644da6 to your computer and use it in GitHub Desktop.
Revisions
-
eugeneyan created this gist
Apr 26, 2021 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,14 @@ for i in xrange(0, len(u2items)): wi = math.pow(len(u2items[i]) + 5, -0.35) for j in xrange(i + 1, len(u2items)): intersection = u2items[i] & u2items[j] wj = wi * math.pow(len(u2items[j]) + 5, -0.35) for product_id in intersection: i2i[product_id] = i2i.get(product_id, 0.0) + wj / (1 + len(intersection)) # u2items = array of users and their items # u2items[i] = items user i clicked on # u2items[j] = items user j clicked on # intersection = items both user i and user j clicked on # wj = product-pair score # i2i is incrementally updated as we loop through users (we won't use a loop in production)