Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Matrix factorization

29 views

Published on

How does Netflix recommend movies? In this presentation we go over a very common technique for recommendations called matrix factorization to predict what rating a user will give a movie. It sounds like a complicated mathematical concept, but all it consists of is finding a set of intermediate features such as action, comedy, etc., and using them to help us determine the ratings.

Published in: Technology
  • Be the first to comment

Matrix factorization

  1. 1. Matrix Factorization and Movie Recommendations Luis Serrano @luis_likes_math
  2. 2. Code https://github.com/yanneta/pytorch-tutorials/blob/master/collaborative-filtering-nn.ipynb Yannet Interian @interian
  3. 3. Question: How?
  4. 4. Ana Betty Carlos Netflix Universe Dana Movie 5 Movie 2 Movie 3Movie 1 Movie 4
  5. 5. M1 M2 M3 M4 M5 Netflix ratings Ana Movie 5 M1 M2 M3 M4 M5 4 M1 M2 M3 M4 M5 1 3 2 5 4 2 1 1 1 5 3 2 3 1 5 2 4 1 5 2
  6. 6. M 1 M 2 M 3 M 4 M 5 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 How do humans behave? M 1 M 2 M 3 M 4 M 5 3 1 1 3 1 1 2 4 1 3 3 1 1 3 1 4 3 5 4 4 M 1 M 2 M 3 M 4 M 5 1 3 2 5 4 2 1 1 1 5 3 2 3 1 5 2 4 1 5 2
  7. 7. Dependent Rows and Columns = = A B C M1 M2 M3 M4 M5 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 = D M1 = M2 = M3 = M4 = M5
  8. 8. M 1 M 2 M 3 M 4 M 5 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 How do humans behave? M 1 M 2 M 3 M 4 M 5 3 1 1 3 1 1 2 4 1 3 3 1 1 3 1 4 3 5 4 4 M 1 M 2 M 3 M 4 M 5 1 3 2 5 4 2 1 1 1 5 3 2 3 1 5 2 4 1 5 2
  9. 9. Independent Rows and Columns A B C D M1 M2 M3 M4 M5 M1 M2 M3 M4 M5 1 3 2 5 4 2 1 1 1 5 3 2 3 1 5 2 4 1 5 2
  10. 10. M 1 M 2 M 3 M 4 M 5 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 How do humans behave? M 1 M 2 M 3 M 4 M 5 3 1 1 3 1 1 2 4 1 3 3 1 1 3 1 4 3 5 4 4 M 1 M 2 M 3 M 4 M 5 1 3 2 5 4 2 1 1 1 5 3 2 3 1 5 2 4 1 5 2
  11. 11. Dependent Rows and Columns = A C M1 M2 M3 M4 M5 3 1 1 3 1 1 2 4 1 3 3 1 1 3 1 4 3 5 4 4 M1 M2 M3 M4 M5 3 1 1 3 1 3 1 1 3 1
  12. 12. Dependent Rows and Columns M1 M2 M3 M4 M5 3 1 1 3 1 1 2 4 1 3 3 1 1 3 1 4 3 5 4 4 M1 = M4M1 M2 M3 M4 M5 3 3 1 1 3 3 4 4 Mall Cop Observe and Report
  13. 13. Dependent Rows and Columns M1 M2 M3 M4 M5 3 1 1 3 1 1 2 4 1 3 3 1 1 3 1 4 3 5 4 4 = B + DC M1 M2 M3 M4 M5 1 2 4 1 3 3 1 1 3 1 4 3 5 4 4 I love action movies! I love comedy! I love action and comedy movies!
  14. 14. Dependent Rows and Columns M5 = Average(M2, M3) M1 M2 M3 M4 M5 3 1 1 3 1 1 2 4 1 3 3 1 1 3 1 4 3 5 4 4 M1 M2 M3 M4 M5 1 1 1 2 4 3 1 1 1 3 5 4
  15. 15. Guessing ratings
  16. 16. Recommender Systems = = A B C M1 M2 M3 M4 M5 3 3 3 3 3 3 3 3 3 3 3 3 3 ? 3 3 3 3 3 3 = D M1 = M2 = M3 = M4 = M5 C Movie 4
  17. 17. Recommender Systems = A C M1 M2 M3 M4 M5 3 1 1 3 1 1 2 4 1 3 3 1 1 3 4 3 5 4 4 C Movie 5
  18. 18. Question: How do we figure out all these depencencies?
  19. 19. Answer: Matrix Factorization
  20. 20. Factorization x
  21. 21. Matrix Factorization M1 M2 M3 M4 M5 3 1 1 3 1 1 2 4 1 3 3 1 1 3 1 4 3 5 4 4 this x that =
  22. 22. Features ActionComedy Sexy Canadian Ryan Has a Sad Dog Meryl Streep Big Boat Drama Scary
  23. 23. Features ActionComedy
  24. 24. Dot Product ActionComedy 13 Ana
  25. 25. Dot Product ActionComedy 13 Betty
  26. 26. Dot Product 31 ActionComedy Dana
  27. 27. Categories M1 3 1 M2 1 2 M3 1 4 M4 3 1 M5 1 3 Ana Movie 1 3 + 1 = 3
  28. 28. Categories M1 3 1 M2 1 2 M3 1 4 M4 3 1 M5 1 3 Movie 1 Betty 3 + 1 = 1
  29. 29. Categories M1 3 1 M2 1 2 M3 1 4 M4 3 1 M5 1 3 Dana Movie 5 1 + 3 = 4
  30. 30. Matrix Factorization M1 3 1 M2 1 2 M3 1 4 M4 3 1 M5 1 3 = M1 M2 M3 M4 M5 3 1 1 3 1 1 2 4 1 3 3 1 1 3 1 4 3 5 4 4
  31. 31. Factorization x
  32. 32. Matrix Factorization M1 M2 M3 M4 M5 3 1 1 3 1 1 2 4 1 3 M1 M2 M3 M4 M5 3 1 1 3 1 1 2 4 1 3 3 1 1 3 1 4 3 5 4 4
  33. 33. Matrix Factorization M1 M2 M3 M4 M5 3 1 1 3 1 1 2 4 1 3 M1 M2 M3 M4 M5 3 1 1 3 1 1 2 4 1 3 3 1 1 3 1 4 3 5 4 4
  34. 34. Matrix Factorization M1 M2 M3 M4 M5 3 1 1 3 1 1 2 4 1 3 M1 M2 M3 M4 M5 3 1 1 3 1 1 2 4 1 3 3 1 1 3 1 4 3 5 4 4
  35. 35. Matrix Factorization M1 M2 M3 M4 M5 3 1 1 3 1 1 2 4 1 3 M1 M2 M3 M4 M5 3 1 1 3 1 1 2 4 1 3 3 1 1 3 1 4 3 5 4 4
  36. 36. Matrix Factorization M1 M2 M3 M4 M5 3 1 1 3 1 1 2 4 1 3 M1 M2 M3 M4 M5 3 1 1 3 1 1 2 4 1 3 3 1 1 3 1 4 3 5 4 4
  37. 37. Storage
  38. 38. Matrix Factorization M1 M2 M3 M4 M5 3 1 1 3 1 1 2 4 1 3 M1 M2 M3 M4 M5 3 1 1 3 1 1 2 4 1 3 3 1 1 3 1 4 3 5 4 4
  39. 39. Matrix Factorization 2000 x 1000 2M entries 100 x 1000 100K entries 2000 x 100 200K entries 2000 Users 1000 Movies 100 Features 100 Features 2000 Users 1000 Movies
  40. 40. Quiz: How many parameters (arrows)? 20 parameters 18 parameters
  41. 41. 2000 users 1000 movies 2000 x 1000 = 2,000,000 parameters Quiz: How many parameters?
  42. 42. 2000 users 1000 movies 300,000 parameters 2000x100 = 200,000 parameters 100 x 1000 = 100,000 parameters Quiz: How many parameters? 100 features
  43. 43. Storage? 2M parameters 300K parameters
  44. 44. How to find the right factorization?
  45. 45. ? Nope Training models
  46. 46. ? Nope Training models
  47. 47. Training models ? Close enough! Training models
  48. 48. Gradient Descent
  49. 49. Matrix Factorization M1 M2 M3 M4 M5 3 1 1 3 1 1 2 4 1 3 1 0 0 1 1 0 1 1 M1 M2 M3 M4 M5 3 1 1 3 1 1 2 4 1 3 3 1 1 3 1 4 3 5 4 4 1 0
  50. 50. M1 M2 M3 M4 M5 F1 1.2 3.1 0.3 2.5 0.2 F2 2.4 1.5 4.4 0.4 1.1 M1 M2 M3 M4 M5 M1 M2 M3 M4 M5 3 1 1 3 1 1 2 4 1 3 3 1 1 3 1 4 3 5 4 4 F1 F2 0.2 0.5 0.3 0.4 0.7 0.8 0.4 0.5 M1 M2 M3 M4 M5 1.44 1.37 2.26 0.7 0.59 1.32 1.53 1.85 0.91 0.5 2.76 3.37 3.73 2.07 1.02 1.68 1.99 2.32 1.2 0.63 1.2 x 0.2 + 2.4 x 0.5 = 1.44
  51. 51. M1 M2 M3 M4 M5 F1 1.2 3.1 0.3 2.5 0.2 F2 2.4 1.5 4.4 0.4 1.1 M1 M2 M3 M4 M5 1.44 1.37 2.26 0.7 0.59 1.32 1.53 1.85 0.91 0.5 2.76 3.37 3.73 2.07 1.02 1.68 1.99 2.32 1.2 0.63 M1 M2 M3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 M5 3 1 1 3 1 1 2 4 1 3 3 1 1 3 1 4 3 5 4 4 3.1 x 0.3 + 1.5 x 0.6 = 1.83
  57. 57. Error function
  58. 58. ? Nope! Training models
  59. 59. You were wrong by 10.3 ? Training models
  60. 60. You were wrong by 5.32 ? Training models
  61. 61. Training models You were wrong by 1.23 ?
  62. 62. Matrix Factorization M1 M2 M3 M4 M5 3 1 1 3 1 1 2 4 1 3 1 0 0 1 1 0 1 1 M1 M2 M3 M4 M5 3 1 1 3 1 1 2 4 1 3 3 1 1 3 1 4 3 5 4 4
  63. 63. F1 F2 0.2 0.5 0.3 0.4 0.7 0.8 0.4 0.5 M1 M2 M3 M4 M5 F1 1.2 3.1 0.3 2.5 0.2 F2 2.4 1.5 4.4 0.4 1.1 M1 M2 M3 M4 M5 1.44 M1 M2 M3 M4 M5 3 1 1 3 1 1 2 4 1 3 3 1 1 3 1 4 3 5 4 4 Error Function Error = (3 - 1.44) 2
  64. 64. F1 F2 0.2 0.5 0.3 0.4 0.7 0.8 0.4 0.5 M1 M2 M3 M4 M5 F1 1.2 3.1 0.3 2.5 0.2 F2 2.4 1.5 4.4 0.4 1.1 M1 M2 M3 M4 M5 1.44 1.37 M1 M2 M3 M4 M5 3 1 1 3 1 1 2 4 1 3 3 1 1 3 1 4 3 5 4 4 Error Function Error = (3 - 1.44) 2 + (1 - 1.37) 2 + … Derivative
  65. 65. Summary: How to use this?
  66. 66. M1 M2 M3 M4 M5 F1 3 1 1 3 1 F2 1 2 4 1 3 F1 F2 1 0 0 1 1 0 1 1 M1 M2 M3 M4 M5 3 1 1 1 4 1 3 1 3 1 3 4 4 M1 M2 M3 M4 M5 1 3 2 3 1 4 5 D M3
  67. 67. Thank you! Luis Serrano @luis_likes_math www.youtube.com/c/LuisSerrano luisguiserrano.github.io www.udacity.com

×