Algorithms package¶
Module Contents¶
This section contains detailed documentation of the algorithms package, encompassing a variety of modules designed for generating recommendations.
algorithms.collaborative_filtering_web module¶
- algorithms.collaborative_filtering_web.aggregate_interactions(interactions, candidate_ids)¶
Aggregates interaction data to calculate a score for each candidate based on likes and superlikes received from the target user. The purpose is to find which candidates have been interacted with most in order to recommend them to the user.
Args:
interactions (list): A list of tuples containing interaction data (user_id, interaction_type).
candidate_ids (list): A list of candidate user IDs to aggregate interactions for.
Returns:
dict: A dictionary mapping candidate IDs to their aggregated interaction scores.
- algorithms.collaborative_filtering_web.collab_filtering(cur, candidate_ids, top_matches, n)¶
Implements collaborative filtering to identify top ‘n’ candidates based on user interactions. Fetches and aggregates interaction data, then selects the candidates with the highest interaction scores.
Args:
cur: Database cursor for executing SQL queries.
candidate_ids (list): A list of candidate user IDs for filtering.
top_matches (list): A list of top matched user IDs.
n (int): Number of top candidates to return.
Returns:
list: A list of top ‘n’ candidate user IDs based on aggregated interaction scores.
- algorithms.collaborative_filtering_web.fetch_user_interactions(cur, top_matches)¶
Retrieves interactions of types ‘liked’ and ‘superliked’ for users with similar preferences to the target user for use in collab filtering.
Args:
cur: Database cursor for executing SQL queries.
top_matches (list): A list of user IDs representing the top matches.
Returns:
list: A list of tuples with user interactions (user_id, interaction_type).
algorithms.web_recommendations module¶
- algorithms.web_recommendations.api_recommendations(request_data, user_id, conn, cur)¶
Handles the API request for generating user recommendations.
Args:
request_data (dict): Data from the API request (contains user interactions).
user_id (int): ID of the user requesting recommendations.
conn: Database connection object.
cur: Database cursor for executing SQL queries.
Returns:
list: JSON formatted list of recommendations.
Before obtaining formatted recommendations from “get_recommendations_for_user” this function checks for any interactions sent from the front end in order to update the users preferences.
- algorithms.web_recommendations.get_recommendations_for_user(cur, conn, user_id, generate=True)¶
Fetches personalized recommendations for a specific user based on their preferences and then formats the recommendations by querying the database for return to the front end.
Args:
cur: Database cursor for executing SQL queries.
conn: Database connection object.
user_id (int): ID of the user for whom recommendations are being fetched.
generate (Booleon): Indicator for the need of generated recommendations or fetched recommendations.
Returns:
list: A list of formatted recommendations including user details.
- algorithms.web_recommendations.mixed_filtering(user_id, cur, conn, filters, filter_uni, filter_prof, n=125)¶
Performs multiple forms of recommendation generation to generate personalized recommendations for a user. Combines collaborative filtering, content-based filtering, and random selection.
Args:
user_id (int): ID of the current user.
cur: Database cursor for executing SQL queries.
conn: Database connection object.
filters (dict): Dictionary of user-specific filtering criteria.
filter_uni (bool): Flag to indicate if university-based filtering is applied.
filter_prof (bool): Flag to indicate if profession-based filtering is applied.
n (int, optional): Number of recommendations to generate. Default is 125.
Returns:
list: List of recommended user IDs after applying mixed filtering.
See Also¶
Note
For a complete overview of all modules, visit the modules overview page.