0
0
ML Pythonml~20 mins

Matrix factorization basics in ML Python - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Matrix Factorization Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
What is the main goal of matrix factorization in machine learning?

Matrix factorization is often used in recommendation systems and dimensionality reduction. What is the primary goal when applying matrix factorization?

ATo randomly shuffle the elements of the matrix to improve randomness
BTo decompose a matrix into product of two or more matrices to capture latent features
CTo convert a matrix into a single vector for easier processing
DTo increase the size of the original matrix by adding more rows and columns
Attempts:
2 left
💡 Hint

Think about how matrix factorization helps reveal hidden patterns or features.

Predict Output
intermediate
2:00remaining
Output of matrix multiplication after factorization

Given matrices U and V below, what is the product U x V?

ML Python
import numpy as np
U = np.array([[1, 2], [3, 4]])
V = np.array([[2, 0], [1, 3]])
result = U @ V
print(result)
A
[[2 3]
 [6 7]]
B
[[4 6]
 [8 12]]
C
[[2 6]
 [3 12]]
D
[[4 6]
 [10 12]]
Attempts:
2 left
💡 Hint

Recall how matrix multiplication works: multiply rows of U by columns of V and sum.

Hyperparameter
advanced
2:00remaining
Choosing the rank (k) in matrix factorization

In matrix factorization, the rank k controls the number of latent features. What is a common effect of choosing a very large k?

AThe model will underfit and fail to capture important patterns
BThe model will always perform better with no downsides
CThe model may overfit the training data and lose generalization
DThe model will ignore the latent features and use raw data only
Attempts:
2 left
💡 Hint

Think about what happens when a model is too complex for the data.

Metrics
advanced
2:00remaining
Evaluating matrix factorization with RMSE

After training a matrix factorization model, you calculate the Root Mean Squared Error (RMSE) on test data. What does a lower RMSE indicate?

AThe predicted values are closer to the actual values, indicating better performance
BThe model predictions are more random and less reliable
CThe model is underfitting and missing important patterns
DThe model has a higher bias and lower variance
Attempts:
2 left
💡 Hint

RMSE measures the average difference between predicted and actual values.

🔧 Debug
expert
2:00remaining
Identifying error in matrix factorization code snippet

What error will this Python code raise when performing matrix factorization using numpy?

ML Python
import numpy as np
R = np.array([[5, 3], [4, 0], [1, 1]])
U = np.random.rand(3, 2)
V = np.random.rand(2, 3)
P = U @ V
print(P)
ANo error, prints a 3x3 matrix
BTypeError: unsupported operand type(s) for @: 'list' and 'list'
CValueError: shapes (3,2) and (3,2) not aligned: 2 (dim 1) != 3 (dim 0)
DIndexError: index out of bounds
Attempts:
2 left
💡 Hint

Check the shapes of matrices U and V before multiplication.