Skip to content

Instantly share code, notes, and snippets.

@DozenCoder
Last active April 27, 2018 05:33
Show Gist options
  • Save DozenCoder/940ee462f5311a4b4bd18189aef1a23e to your computer and use it in GitHub Desktop.
Save DozenCoder/940ee462f5311a4b4bd18189aef1a23e to your computer and use it in GitHub Desktop.

Revisions

  1. Dabu Zhang revised this gist Apr 27, 2018. 1 changed file with 5 additions and 2 deletions.
    7 changes: 5 additions & 2 deletions similarity.py
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,9 @@
    # similarity method 1
    sim = 0
    sim = sum([math.pow(r1[i] - r2[i]) for i in user_comm])/len(user_comm)
    sim = sum([math.pow(r1[i] - r2[i]) for i in item_comm])/len(item_comm)
    sim = math.sqrt(sim)
    sim = 1.0 - math.tanh(sim)


    # similarity method 2
    max_comm = min(len(user1), len(user2))
    sim = sim * item_comm / max_comm
  2. Dabu Zhang created this gist Apr 27, 2018.
    6 changes: 6 additions & 0 deletions similarity.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    sim = 0
    sim = sum([math.pow(r1[i] - r2[i]) for i in user_comm])/len(user_comm)
    sim = math.sqrt(sim)
    sim = 1.0 - math.tanh(sim)