Skip to content

Support hyper-parameter search for next-item recommenders (#643)#702

Open
nsiddharth wants to merge 1 commit into
PreferredAI:masterfrom
nsiddharth:fix/643-next-item-hyperopt
Open

Support hyper-parameter search for next-item recommenders (#643)#702
nsiddharth wants to merge 1 commit into
PreferredAI:masterfrom
nsiddharth:fix/643-next-item-hyperopt

Conversation

@nsiddharth

Copy link
Copy Markdown

Description

GridSearch and RandomSearch (cornac.hyperopt) could not be used to tune NextItemRecommender models evaluated with NextItemEvaluation. Two issues blocked it:

  1. The search wrapper was rejected by the evaluator. NextItemEvaluation.evaluate() requires its model to be a NextItemRecommender, but a GridSearch/RandomSearch object is a Recommender wrapper, not a NextItemRecommender. It raised:

    ValueError: model must be a NextItemRecommender but '<class 'cornac.hyperopt.RandomSearch'>' is provided
    
  2. The search loop scored next-item models with the wrong evaluator. Inside BaseSearch.fit, ranking metrics fell through to the standard ranking_eval, whose rank()/score() path is incompatible with the session-based signature score(user_idx, history_items, ...):

    TypeError: SPop.score() missing 1 required positional argument: 'history_items'
    

Fix:

  • NextItemEvaluation.evaluate() now also accepts a search wrapper whose .model is a NextItemRecommender.
  • BaseSearch.fit() routes NextItemRecommender candidates through next_item_evaluation.ranking_eval, passing the eval method's exclude_unknowns and mode.
  • BaseSearch delegates transform/score/rank to the selected best_model, so the fitted wrapper evaluates transparently on the test set.

This is additive — the existing rating/standard-ranking search paths are unchanged (verified by the pre-existing test_grid_search/test_random_search).

Related Issues

Fixes #643.

Checklist:

  • I have added tests.
  • I have updated the documentation accordingly.
  • I have updated README.md (if you are adding a new model).
  • I have updated examples/README.md (if you are adding a new example).
  • I have updated datasets/README.md (if you are adding a new dataset).

…I#643)

GridSearch/RandomSearch could not tune NextItemRecommender models
evaluated with NextItemEvaluation:
  - NextItemEvaluation.evaluate() rejected the search wrapper because
    it is a Recommender, not a NextItemRecommender.
  - BaseSearch.fit() scored next-item models with the standard
    ranking_eval, whose rank()/score() path is incompatible with the
    session-based score(history_items=...) signature.

Fix:
  - Accept a search wrapper whose .model is a NextItemRecommender.
  - Route next-item models through next_item_evaluation.ranking_eval
    during search, using the eval_method's exclude_unknowns/mode.
  - Delegate transform/score/rank from BaseSearch to the best model
    so the fitted wrapper evaluates transparently.

Add GridSearch/RandomSearch next-item tests.
@qtuantruong qtuantruong requested a review from hieuddo June 11, 2026 00:15
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.

[BUG] Hyperparameter tuning for next item recommenders

1 participant