Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Recommendation.jl: Building Recommender Systems...

Recommendation.jl: Building Recommender Systems in Julia

Takuya Kitazawa

July 23, 2019
Tweet

More Decks by Takuya Kitazawa

Other Decks in Programming

Transcript

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

    Explicit: Ra)ng feedback Implicit: Unary feedback
  2. • 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
  3. 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
  4. • 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)
  5. And more! SVD & Matrix Factoriza)on (MF) SVD(data, k) recommender

    = MF(data, k) build!(recommender, learning_rate=1e-3, max_iter=100)
  6. 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
  7. 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
  8. 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
  9. 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
  10. 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