Problem Matrix factorization for approximating products how do we solve such that Z approximates products N, M. How to define the math formula for solve for Z approximtaes the products of N,M?
Scenario Given matrix that has product N, product M.
Proposal to problem Need a math solution to define the a problem which can be to make a prediction on product N, or M to determine if there are features that are latent.
Constraints NMF exhibits constraints which: W≥0 and H≥0 products can be defined by a k-dimensional vector R with lower dimension that the original R with nm dimensions. Hence, R with nM = (W with nr) (H with rm)
Author Level This math is for a entry level understanding on how to use matrix factorization for products N, M, to factor Z into approximations on the product N, M.
Proposed code solution 1 Computes an approximation of the user-item matrix Z as the product of matrices N and M
def matrix_approximation(N, M):
Z = np.dot(N, M)
return Z
Proposed code solution 2 to treat N to factor M product
def matrix_factorization(Z, k, steps=50, alpha=0.0002, beta=0.02):
m, n = Z.shape
N = np.random.rand(m, k)
M = np.random.rand(k, n)
for step in range(steps):
for i in range(m):
for j in range(n):
if Z[i, j] > 0:
eij = Z[i, j] - np.dot(N[i,:], M[:,j])
for r in range(k):
N[i, r] = N[i, r] + alpha * (2 * eij * M[r, j] - beta * N[i, r])
M[r, j] = M[r, j] + alpha * (2 * eij * N[i, r] - beta * M[r, j])
e = 0
for i in range(m):
for j in range(n):
if Z[i, j] > 0:
e = e + pow(Z[i, j] - np.dot(N[i,:], M[:,j]), 2)
for r in range(k):
e = e + (beta/2) * (pow(N[i,r],2) + pow(M[r,j],2))
if e < 0.001:
break
return N, M
```