Recommendation Algorithm with surprise SVD

123 views Asked by At

I am trying to implement a collaborative filtering algorithm to get predictions for new users, that have not been in the training dataset. However ChatGBT isn't a real help with this. Is there another way, without retraining the model, to predict what the user would rate all items inside the dataset based off 2 or 3 items he provided, that he liked. I am fairly new to collaborative filtering, sorry, perhaps this is the wrong approach. I am very keen on listening to feedback. Thank you in advance.

In case it helps, here is my current approach, that sadly doesn't include the new user, so it just guesses without any regards towards the provided ratings.

data = load_trainings_data()
        trainset = data.build_full_trainset()

        # Embed user preferences
        st.info("Embedding user preferences...")
        user_id = trainset.n_users
        user_ratings = [(user_id, trainset.to_inner_iid(item_id), 5) for item_id in selected_ids]
        trainset_new = trainset.build_testset()
        trainset_new += user_ratings

        # Use the SVD model to predict 
        item_ids = trainset.all_items()
        predictions = [algo.predict(user_id, item_id) for item_id in item_ids]

        # Rank and print the recommendations
        recommended_items = sorted(predictions, key=lambda x: x.est, reverse=True)
        top_recommendations = recommended_items[:10]  # Get top 10 recommendations

        for recommendation in top_recommendations:
            item_id = recommendation.iid
            print(f'Recommended item: {item_id}')

        print(f"Top 10 recommendations for user {user_id}:")
        for recommendation in top_recommendations:
            #item_id = trainset.to_raw_iid(recommendation.iid, True)
            print(f'Recommended item: {recommendation}')

        # Rank and print the recommendations
        st.info("Ranking recommendations...")
        recommended_items = sorted(predictions, key=lambda x: x.est, reverse=True)
        top_recommendations = recommended_items[:10]  # Get top 10 recommendations

        for recommendation in top_recommendations:
            item_id = recommendation.iid
            print(f'Recommended item: {item_id}')

        print(f"Top 10 recommendations for user {user_id}:")
        for recommendation in top_recommendations:
            #item_id = trainset.to_raw_iid(recommendation.iid, True)
            print(f'Recommended item: {recommendation}')
0

There are 0 answers