Your question is Matrix Factorization Recommendation. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Amazon Personalize needs a lightweight collaborative-filtering baseline for recommending items from Amazon Shopping interaction data. Implement matrix factorization using stochastic gradient descent, then return the highest-scoring unseen items for every user.
The input ratings is a rectangular list of lists. A positive value represents an observed rating, while -1 represents a missing rating. Initialize user and item factors deterministically using the formulas 0.1 * (1 + ((user_index + factor_index) % 3)) and 0.1 * (1 + ((item_index + 2 * factor_index) % 3)). For each observed rating r, update the factors using the prediction error r - dot(user_vector, item_vector), learning rate, and L2 regularization. Repeat for epochs passes in row-major order.
Return one list of item indices per user. Each list must contain at most k unseen items, sorted by decreasing predicted score. Break equal-score ties by smaller item index.
Input: ratings, a nonempty m x n matrix of floats; k, num_factors, epochs, learning_rate, and regularization, all numeric parameters. Output: a list of m lists containing item indices.
def recommend_items(ratings, k, num_factors, epochs, learning_rate, regularization):