Advertisement

Matrix factorization

Jul. 3, 2019
Advertisement

More Related Content

Advertisement

Matrix factorization

  1. Matrix Factorization and Movie Recommendations Luis Serrano @luis_likes_math
  2. Code https://github.com/yanneta/pytorch-tutorials/blob/master/collaborative-filtering-nn.ipynb Yannet Interian @interian
  3. Question: How?
  4. Ana Betty Carlos Netflix Universe Dana Movie 5 Movie 2 Movie 3Movie 1 Movie 4
  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. 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. 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. 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. 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. 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. 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. 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. 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. 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. Guessing ratings
  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. 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. Question: How do we figure out all these depencencies?
  19. Answer: Matrix Factorization
  20. Factorization x
  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. Features ActionComedy Sexy Canadian Ryan Has a Sad Dog Meryl Streep Big Boat Drama Scary
  23. Features ActionComedy
  24. Dot Product ActionComedy 13 Ana
  25. Dot Product ActionComedy 13 Betty
  26. Dot Product 31 ActionComedy Dana
  27. Categories M1 3 1 M2 1 2 M3 1 4 M4 3 1 M5 1 3 Ana Movie 1 3 + 1 = 3
  28. Categories M1 3 1 M2 1 2 M3 1 4 M4 3 1 M5 1 3 Movie 1 Betty 3 + 1 = 1
  29. Categories M1 3 1 M2 1 2 M3 1 4 M4 3 1 M5 1 3 Dana Movie 5 1 + 3 = 4
  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. Factorization x
  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. 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. 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. 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. 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. Storage
  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. 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. Quiz: How many parameters (arrows)? 20 parameters 18 parameters
  41. 2000 users 1000 movies 2000 x 1000 = 2,000,000 parameters Quiz: How many parameters?
  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. Storage? 2M parameters 300K parameters
  44. How to find the right factorization?
  45. ? Nope Training models
  46. ? Nope Training models
  47. Training models ? Close enough! Training models
  48. Gradient Descent
  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. 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. 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 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
  52. 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 1.2 x 0.2 + 2.4 x 0.5 = 1.44
  53. F1 F2 0.3 0.6 0.3 0.4 0.7 0.8 0.4 0.5 M1 M2 M3 M4 M5 F1 1.4 3.1 0.3 2.5 0.2 F2 2.5 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
  54. F1 F2 0.3 0.6 0.3 0.4 0.7 0.8 0.4 0.5 M1 M2 M3 M4 M5 F1 1.4 3.1 0.3 2.5 0.2 F2 2.5 1.5 4.4 0.4 1.1 M1 M2 M3 M4 M5 1.92 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.4 x 0.3 + 2.5 x 0.6 = 1.92
  55. F1 F2 0.3 0.6 0.3 0.4 0.7 0.8 0.4 0.5 M1 M2 M3 M4 M5 F1 1.4 3.1 0.3 2.5 0.2 F2 2.5 1.5 4.4 0.4 1.1 M1 M2 M3 M4 M5 1.92 1.83 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.4 x 0.3 + 2.5 x 0.6 = 1.92
  56. M1 M2 M3 M4 M5 F1 1.4 3.1 0.3 2.5 0.2 F2 2.5 1.5 4.4 0.4 1.1 F1 F2 0.3 0.6 0.3 0.4 0.7 0.8 0.4 0.5 M1 M2 M3 M4 M5 1.92 1.83 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 3.1 x 0.3 + 1.5 x 0.6 = 1.83
  57. Error function
  58. ? Nope! Training models
  59. You were wrong by 10.3 ? Training models
  60. You were wrong by 5.32 ? Training models
  61. Training models You were wrong by 1.23 ?
  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. 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. 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. Summary: How to use this?
  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. Thank you! Luis Serrano @luis_likes_math www.youtube.com/c/LuisSerrano luisguiserrano.github.io www.udacity.com
Advertisement