dialoguekit.core.recsys.ratings

Represents item ratings and provides access either based on items or users.

Ratings are normalized in the [-1,1] range, where -1 corresponds to (strong) dislike, 0 is neutral, and 1 is (strong) like.

Classes

Ratings

Initializes a ratings instance.

Module Contents

class dialoguekit.core.recsys.ratings.Ratings(item_collection: dialoguekit.core.recsys.item_collection.ItemCollection = None)

Initializes a ratings instance.

Parameters:

item_collection (optional) – If provided, only ratings on items in ItemCollection are accepted.

load_ratings_csv(file_path: str, delimiter: str = ',', min_rating: float = 0.5, max_rating: float = 5.0) None

Loads ratings from a csv file.

The file is assumed to have userID, itemID, and rating columns (following the MovieLens format). Additional columns that may be present are ignored. UserID and itemID are strings, rating is a float.

Ratings are assumed to be given in the [min_rating, max_rating] range, which gets normalized into the [-1,1] range. (Default min/max rating values are based on the MovieLens collection.)

If an ItemCollection is provided in the constructor, then ratings are filtered to items that are present in the collection.

Parameters:
  • file_path – Path to CSV file.

  • delimiter – Field separator (default: comma).

  • min_rating – Minimum rating (default: 0.5).

  • max_rating – Maximum rating (default: 5.0).

get_user_ratings(user_id: str) Dict[str, float]

Returns all ratings of a given user.

Parameters:

user_id – User ID.

Returns:

Dictionary with item IDs as keys and ratings as values.

get_item_ratings(item_id: str) Dict[str, float]

Returns all ratings given to a specific item.

Parameters:

item_id – Item ID.

Returns:

Dictionary with user IDs as keys and ratings as values.

get_user_item_rating(user_id: str, item_id: str) float | None

Returns the rating by a given user on a specific item.

Parameters:
  • user_id – User ID.

  • item_id – Item ID.

Returns:

Rating as float or None.

get_random_user_id() str

Returns a random user ID.

Returns:

User ID.