LoslegenKostenlos loslegen

Non-negative matrix factorization

It's possible for one matrix to have two equally close factorizations where one has all positive values and the other has some negative values.

The matrix M has been factored twice using two different factorizations. Take a look at each pair of factor matrices L and U, and W and H to see the differences. Then use their products to see that they produce essentially the same product.

Diese Übung ist Teil des Kurses

Building Recommendation Engines with PySpark

Kurs anzeigen

Anleitung zur Übung

  • Use print() to view the L and U matrices. Notice that some values in matrices L and U are negative.
  • Use print() to view the W and H matrices. Notice that all values in these two matrices are positive.
  • The L and U matrices and W and H matrices have been multiplied together to produce the LU and WH matrices respectively. Use getRMSE(product_matrix, original_matrix) to see how close LU is to M compared to how close WH is to M. Are they similar?

Interaktive Übung

Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.

# View the L, U, W, and H matrices.
print("Matrices L and U:") 
print(____)
print(____)

print("Matrices W and H:")
print(____)
print(____)

# Calculate RMSE between LU and M
print("RMSE of LU: ", getRMSE(____, ____))

# Calculate RMSE between WH and M
print("RMSE of WH: ", getRMSE(____, ____))
Code bearbeiten und ausführen