Skip to content

can't render content-based recommendation on frontend. #83

Open
tindo2003 wants to merge 1 commit intopractical-recommender-systems:masterfrom
tindo2003:builder/lda_model_calculator.py
Open

can't render content-based recommendation on frontend. #83
tindo2003 wants to merge 1 commit intopractical-recommender-systems:masterfrom
tindo2003:builder/lda_model_calculator.py

Conversation

@tindo2003
Copy link

@tindo2003 tindo2003 commented Jan 16, 2025

I modified builder/lda_model_calculator.py as follows:

x_id = str(docs[x].movie_id)
y_id = str(docs[y].movie_id)

was updated to:

x_id = str(docs[x].imdb_id)
y_id = str(docs[y].imdb_id)

Reason for the change:
In recs/content_based_recommender.py, the function recommend_items_by_ratings returns data in the following structure:

{
    [
        <target_id>,
        {
            "prediction": "9.5500",
            "sim_items": [
                <source_id>, <source_id>, ...
            ]
        }
    ]
}

The frontend template /templates/moviegeek/index.html expects <target_id> to be an IMDb ID so it can use the get_url() function in base.html to fetch information about the recommended movie.

Previously, the old code could not fetch the correct movie information because the target and source fields in the lda_similarity table of the database stored TMDb IDs instead of IMDb IDs. By changing movie_id to imdb_id, the recommendation system now aligns with the frontend's requirements and ensures proper functionality.

The other cosmestic changes are due to my linter (my bad)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant