Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added users parameter in cross-validate #112

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions rectools/model_selection/cross_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def cross_validate( # pylint: disable=too-many-locals
k: int,
filter_viewed: bool,
items_to_recommend: tp.Optional[ExternalIds] = None,
users: tp.Optional[ExternalIds] = None,
) -> tp.Dict[str, tp.Any]:
"""
Run cross validation on multiple models with multiple metrics.
Expand Down Expand Up @@ -115,6 +116,9 @@ def cross_validate( # pylint: disable=too-many-locals
fold_dataset = _gen_2x_internal_ids_dataset(interactions_df_train, dataset.user_features, dataset.item_features)

interactions_df_test = interactions.df.iloc[test_ids] # 1x internal
if users is not None:
internal_users = dataset.user_id_map.convert_to_internal(users, strict=False)
interactions_df_test = interactions_df_test[interactions_df_test[Columns.User].isin(internal_users)]
test_users = interactions_df_test[Columns.User].unique() # 1x internal
catalog = interactions_df_train[Columns.Item].unique() # 1x internal

Expand Down