Factorization Machines are a type of collaborative filtering algorithm used in recommender systems. They are particularly effective for sparse data. **Example:** Suppose we have a user-item interaction matrix where each entry represents the rating given by a user to an item. We can use Factorization Machines to learn latent factors that capture the interactions between users and items. **Constraints:** The user-item interaction matrix is sparse, meaning most users have interacted with few items. The number of users and items is large. The ratings are mostly binary (0 or 1).
Your task is to implement a Factorization Machine model using NumPy to predict the ratings given by users to items.
Test Cases
Test Case 1
Input:
[[0, 1, 0, 1], [1, 0, 1, 0], [0, 1, 1, 0], [1, 0, 0, 1]]Expected:
[[0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0]]Test Case 2
Input:
[[1, 0, 1, 0], [0, 1, 0, 1], [1, 0, 0, 1], [0, 1, 1, 0]]Expected:
[[0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0]]+ 3 hidden test cases