0
$\begingroup$

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
```
$\endgroup$
3
  • 2
    $\begingroup$ Dear @user1857373, welcome to the site. It is not clear at all what your question is. It seems that you would like to know more about matrix factorization. A google search would give you plenty of information about it. If you have specific questions about that, please specify them clearly. $\endgroup$
    – noe
    Commented Jan 31, 2023 at 22:48
  • $\begingroup$ Thanks Noe, I'm new to the data science stack. For the question, "how to write the math algorithm for NMF to work on solving a matrix factorization for products to be approximated on these products", Or in Python, how to define a matrix factorization for products N, M, to factor Z into approximations on the product N, M" $\endgroup$ Commented Feb 1, 2023 at 2:48
  • 1
    $\begingroup$ A simple google search gives many relevant results, both regarding more theoretical information or more related to implementations. Please, check those. If you have specific questions about that, please feel free to ask here. Otherwise, your question is a bit too open. You can check the help center to see how to improve a question. $\endgroup$
    – noe
    Commented Feb 1, 2023 at 7:54

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.