Click4Ai

517.

Medium

Implement a collaborative filtering algorithm to recommend items to users. Collaborative filtering is a type of recommendation algorithm that uses the behavior of similar users to make recommendations.

Example:

Suppose we have a dataset of user-item interactions, where each row represents a user and each column represents an item. The value in each cell represents the rating given by the user to the item.

Constraints:

The user-item interaction data is provided in a numpy array of shape (n_users, n_items), where n_users is the number of users and n_items is the number of items.

Your task is to implement a collaborative filtering algorithm that takes the user-item interaction data as input and outputs a matrix of recommended items for each user.

You can use the surprise library to implement the collaborative filtering algorithm. You will need to define the algorithm and the parameters used to train it.

Test Cases

Test Case 1
Input: [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
Expected: [[1.0, 2.0, 3.0], [4.0, 5.0, 6.0], [7.0, 8.0, 9.0]]
Test Case 2
Input: [[10, 20, 30], [40, 50, 60], [70, 80, 90]]
Expected: [[10.0, 20.0, 30.0], [40.0, 50.0, 60.0], [70.0, 80.0, 90.0]]
+ 3 hidden test cases