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.
Cet exercice fait partie du cours
Building Recommendation Engines with PySpark
Instructions
- Use
print()to view theLandUmatrices. Notice that some values in matricesLandUare negative. - Use
print()to view theWandHmatrices. Notice that all values in these two matrices are positive. - The
LandUmatrices andWandHmatrices have been multiplied together to produce theLUandWHmatrices respectively. UsegetRMSE(product_matrix, original_matrix)to see how closeLUis toMcompared to how closeWHis toM. Are they similar?
Exercice interactif pratique
Essayez cet exercice en complétant cet exemple de code.
# 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(____, ____))