Recommendation.jl: Building Recommender Systems in Julia

Recommendation.jl: Building Recommender Systems in Julia

37130a5f1550eb2d91e640cedf907a78?s=128

Takuya Kitazawa

July 23, 2019
Tweet

Transcript

  1. Recommenda)on.jl Building Recommender Systems in Julia Takuya Kitazawa

  2. julia> using Pkg; Pkg.add(“Recommendation”) github.com/takuti/Recommendation.jl

  3. mutable struct Event user::Int item::Int value::Float64 end item user value

    Explicit: Ra)ng feedback Implicit: Unary feedback
  4. • User-item matrix: • Series of events for more users/items:

    Data := User-Item Interac)ons using Recommendation using SparseArrays data = DataAccessor(sparse([1 0 0; 4 5 0])) n_user, n_item = 5, 10 events = [Event(1, 2, 1.0), Event(3, 2, 1.0), Event(2, 6, 4.0)] data = DataAccessor(events, n_user, n_item) Explicit ra)ngs
  5. recommender = MostPopular(data) build!(recommender) recommend(recommender, 4, 2, collect(1:n_item)) # for

    user#4, pick top-2 from all items Common interfaces Recommenda5on algorithm data
  6. • Coun)ng frequency of… Most frequently co-observed items with i_ref

    Most frequently observed items • Weigh)ng items by… % of observed values that are greater than th Mean of observed values across all users Mean of observed values across all items Quick math… Non-Personalized Baseline Recommender CoOccurrence(data, i_ref) MostPopular(data) ThresholdPercentage(data, th) UserMean(data) ItemMean(data)
  7. Bit more… Collabora)ve Filtering (CF) UserKNN(data, k) ItemKNN(data, k)

  8. And more! SVD & Matrix Factoriza)on (MF) SVD(data, k) recommender

    = MF(data, k) build!(recommender, learning_rate=1e-3, max_iter=100)
  9. Evalua)on recall = cross_validation( 5, # N-fold Recall, # Metric

    5, # Top-k recommendation MostPopular, # Recommender data, # Data Accessor args… # Hyperparameters ) Ra5ng metric: - MAE - RMSE Ranking metric: - AUC - Mean Average Precision - Mean Percen)le Rank - NDCG - Precision - Recall - Reciprocal Rank
  10. Recommender Systems + Julia = • Vector/matrix-friendly syntax • High

    simplicity and modularity • Efficient numerical compu)ng, especially for matrices • Good ecosystem surrounding mathema)cal tools - Recommender system is not only about ML
  11. Recommender Systems + Julia = … • Integra)on with real-world

    applica)ons - Con)nuously observed new events - Scheduled model update and recommenda)on - Can be real-)me - Scalability
  12. Keep minimal under… But make customizable

  13. using LinearAlgebra using LowRankApprox struct PartialQR <: Recommender data::DataAccessor rank::Int

    Q::AbstractMatrix R::AbstractMatrix p::AbstractVector function PartialQR(data::DataAccessor, rank::Int) n_user, n_item = size(data.R) Q = matrix(n_user, rank) R = matrix(rank, n_item) p = vector(n_item, Int) new(data, rank, Q, R, p) end end JuliaMatrices/LowRankApprox.jl (Hyper-)Parameters
  14. isbuilt(recommender::PartialQR) = isfilled(recommender.Q) function build!(recommender::PartialQR) # NaNs are filled by

    zeros for now R = copy(recommender.data.R) R[isnan.(R)] .= 0 F = pqrfact(R, rank=recommender.rank) recommender.Q[:] = F.Q[:] recommender.R[:] = F.R[:] recommender.p[:] = F.p[:] end function Recommendation.predict(recommender::PartialQR, u::Int, i::Int) check_build_status(recommender) dot(recommender.Q[u, :], recommender.R[:, recommender.p][:, i]) end Low rank approxima)on
  15. julia> using Pkg; Pkg.add(“Recommendation”) github.com/takuti/Recommendation.jl