May 2020
Intermediate to advanced
404 pages
10h 52m
English
We will now create a function to perform matrix factorization. Matrix factorization became a popular family of algorithms used for recommender systems during the Netflix Prize challenge in 2006. It is a family of algorithms that decomposes a user-item matrix into a set of two lower-dimension rectangular matrices that can be multiplied to restore the original higher-order matrix:
def matrix_factorization(R, P, Q, steps=1, gamma=0.001,lamda=0.02): for step in range(steps): for i in R.index: for j in R.columns: if R.loc[i,j]>0: eij=R.loc[i,j]-np.dot(P.loc[i],Q.loc[j]) P.loc[i]=P.loc[i]+gamma*(eij*Q.loc[j]-lamda*P.loc[i]) Q.loc[j]=Q.loc[j]+gamma*(eij*P.loc[i]-lamda*Q.loc[j]) e=0 for i in R.index: for ...
Read now
Unlock full access