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

Basket models #216

Open
wants to merge 31 commits into
base: main
Choose a base branch
from
Open

Basket models #216

wants to merge 31 commits into from

Conversation

julesdesir
Copy link
Collaborator

@julesdesir julesdesir commented Jan 15, 2025

Description of the goal of the PR

Description: add SHOPPER model and Trip / TripDataset data structures

Changes this PR introduces (fill it before implementation)

  • : Trip, TripDataset and SHOPPER
  • : Data preprocessing for basket models
  • : Remove unnecessary enumerate() in for loop
  • : Fix weight of the loss of the last batch in the loss of the whole epoch
  • : Tests for basket models
  • : SHOPPER in readme and in docs

Checklist before requesting a review

  • I have commented my code, particularly in hard-to-understand areas
  • I have typed my code
  • I have created / updated the docstrings
  • I have updated the README, if relevant
  • I have updated the requirements files if a new package is used
  • I have tested my code
  • The CI pipeline passes
  • I have performed a self-review of my code

@julesdesir julesdesir self-assigned this Jan 15, 2025
@julesdesir julesdesir added the new feature Additional feature to be added label Jan 15, 2025
Copy link
Contributor

github-actions bot commented Jan 15, 2025

Coverage

Coverage Report for Python 3.9
FileStmtsMissCoverMissing
choice_learn
   __init__.py20100% 
   tf_ops.py480100% 
choice_learn/basket_models
   shopper.py2808271%72, 76, 89–110, 127, 227, 295, 446, 500, 533, 686–696, 747, 964, 982, 1021, 1035, 1042, 1050–1081, 1116–1146, 1156–1178, 1195–1244
   trip_dataset.py1223472%52, 79, 121, 131, 148–161, 181, 225, 247, 257, 267, 297, 391, 405–423, 528–534
choice_learn/basket_models/utils
   permutation.py22195%35
choice_learn/data
   __init__.py30100% 
   choice_dataset.py6473395%198, 250, 283, 421, 463–464, 589, 724, 738, 840, 842, 937, 957–961, 1140, 1159–1161, 1179–1181, 1209, 1214, 1223, 1240, 1281, 1293, 1307, 1346, 1361, 1366, 1395, 1408, 1443–1444
   indexer.py2392390%20, 31, 45, 60–67, 202–204, 219–230, 265, 291, 577
   storage.py161696%22, 33, 51, 56, 61, 71
   store.py72720%3–275
choice_learn/datasets
   __init__.py40100% 
   base.py393599%43–44, 154–155, 715
   expedia.py1028319%37–301
   tafeng.py490100% 
choice_learn/datasets/data
   __init__.py00100% 
choice_learn/models
   __init__.py14286%15–16
   base_model.py2541295%144, 186, 283, 302, 342, 349, 378, 397, 428–429, 438–439
   baseline_models.py490100% 
   conditional_logit.py2362191%46, 49, 51, 82, 85, 88–92, 95–99, 133, 298, 335, 392, 467–473, 598, 632, 739, 743
   halo_mnl.py124298%186, 374
   latent_class_base_model.py2863986%55–61, 273–279, 288, 325–330, 497–500, 605, 624, 665–701, 715, 720, 751–752, 774–775, 869–870, 974
   latent_class_mnl.py62690%257–261, 296
   learning_mnl.py67396%157, 182, 188
   nested_logit.py2911296%55, 77, 160, 269, 351, 484, 530, 600, 679, 848, 900, 904
   reslogit.py132695%285, 360, 369, 374, 382, 432
   rumnet.py236399%748–751, 982
   simple_mnl.py139696%167, 275, 347, 355, 357, 359
   tastenet.py94397%142, 180, 188
choice_learn/toolbox
   __init__.py00100% 
   assortment_optimizer.py27678%28–30, 93–95, 160–162
   gurobi_opt.py2362360%3–675
   or_tools_opt.py2301195%103, 107, 296–305, 315, 319, 607, 611
TOTAL462170785% 

Tests Skipped Failures Errors Time
144 0 💤 0 ❌ 0 🔥 5m 48s ⏱️

Copy link
Contributor

github-actions bot commented Jan 15, 2025

Coverage

Coverage Report for Python 3.10
FileStmtsMissCoverMissing
choice_learn
   __init__.py20100% 
   tf_ops.py480100% 
choice_learn/basket_models
   shopper.py2808271%72, 76, 89–110, 127, 227, 295, 446, 500, 533, 686–696, 747, 964, 982, 1021, 1035, 1042, 1050–1081, 1116–1146, 1156–1178, 1195–1244
   trip_dataset.py1223472%52, 79, 121, 131, 148–161, 181, 225, 247, 257, 267, 297, 391, 405–423, 528–534
choice_learn/basket_models/utils
   permutation.py22195%35
choice_learn/data
   __init__.py30100% 
   choice_dataset.py6473395%198, 250, 283, 421, 463–464, 589, 724, 738, 840, 842, 937, 957–961, 1140, 1159–1161, 1179–1181, 1209, 1214, 1223, 1240, 1281, 1293, 1307, 1346, 1361, 1366, 1395, 1408, 1443–1444
   indexer.py2392390%20, 31, 45, 60–67, 202–204, 219–230, 265, 291, 577
   storage.py161696%22, 33, 51, 56, 61, 71
   store.py72720%3–275
choice_learn/datasets
   __init__.py40100% 
   base.py393499%39, 154–155, 715
   expedia.py1028319%37–301
   tafeng.py490100% 
choice_learn/datasets/data
   __init__.py00100% 
choice_learn/models
   __init__.py14286%15–16
   base_model.py2541295%144, 186, 283, 302, 342, 349, 378, 397, 428–429, 438–439
   baseline_models.py490100% 
   conditional_logit.py2362191%46, 49, 51, 82, 85, 88–92, 95–99, 133, 298, 335, 392, 467–473, 598, 632, 739, 743
   halo_mnl.py124298%186, 374
   latent_class_base_model.py2863986%55–61, 273–279, 288, 325–330, 497–500, 605, 624, 665–701, 715, 720, 751–752, 774–775, 869–870, 974
   latent_class_mnl.py62690%257–261, 296
   learning_mnl.py67396%157, 182, 188
   nested_logit.py2911296%55, 77, 160, 269, 351, 484, 530, 600, 679, 848, 900, 904
   reslogit.py132695%285, 360, 369, 374, 382, 432
   rumnet.py236399%748–751, 982
   simple_mnl.py139696%167, 275, 347, 355, 357, 359
   tastenet.py94397%142, 180, 188
choice_learn/toolbox
   __init__.py00100% 
   assortment_optimizer.py27678%28–30, 93–95, 160–162
   gurobi_opt.py2382380%3–675
   or_tools_opt.py2301195%103, 107, 296–305, 315, 319, 607, 611
TOTAL462370885% 

Tests Skipped Failures Errors Time
144 0 💤 0 ❌ 0 🔥 6m 11s ⏱️

Copy link
Contributor

github-actions bot commented Jan 15, 2025

Coverage

Coverage Report for Python 3.11
FileStmtsMissCoverMissing
choice_learn
   __init__.py20100% 
   tf_ops.py480100% 
choice_learn/basket_models
   shopper.py2808271%72, 76, 89–110, 127, 227, 295, 446, 500, 533, 686–696, 747, 964, 982, 1021, 1035, 1042, 1050–1081, 1116–1146, 1156–1178, 1195–1244
   trip_dataset.py1223472%52, 79, 121, 131, 148–161, 181, 225, 247, 257, 267, 297, 391, 405–423, 528–534
choice_learn/basket_models/utils
   permutation.py22195%35
choice_learn/data
   __init__.py30100% 
   choice_dataset.py6473395%198, 250, 283, 421, 463–464, 589, 724, 738, 840, 842, 937, 957–961, 1140, 1159–1161, 1179–1181, 1209, 1214, 1223, 1240, 1281, 1293, 1307, 1346, 1361, 1366, 1395, 1408, 1443–1444
   indexer.py2392390%20, 31, 45, 60–67, 202–204, 219–230, 265, 291, 577
   storage.py161696%22, 33, 51, 56, 61, 71
   store.py72720%3–275
choice_learn/datasets
   __init__.py40100% 
   base.py393499%39, 154–155, 715
   expedia.py1028319%37–301
   tafeng.py490100% 
choice_learn/datasets/data
   __init__.py00100% 
choice_learn/models
   __init__.py14286%15–16
   base_model.py2541295%144, 186, 283, 302, 342, 349, 378, 397, 428–429, 438–439
   baseline_models.py490100% 
   conditional_logit.py2362191%46, 49, 51, 82, 85, 88–92, 95–99, 133, 298, 335, 392, 467–473, 598, 632, 739, 743
   halo_mnl.py124298%186, 374
   latent_class_base_model.py2863986%55–61, 273–279, 288, 325–330, 497–500, 605, 624, 665–701, 715, 720, 751–752, 774–775, 869–870, 974
   latent_class_mnl.py62690%257–261, 296
   learning_mnl.py67396%157, 182, 188
   nested_logit.py2911296%55, 77, 160, 269, 351, 484, 530, 600, 679, 848, 900, 904
   reslogit.py132695%285, 360, 369, 374, 382, 432
   rumnet.py236399%748–751, 982
   simple_mnl.py139696%167, 275, 347, 355, 357, 359
   tastenet.py94397%142, 180, 188
choice_learn/toolbox
   __init__.py00100% 
   assortment_optimizer.py27678%28–30, 93–95, 160–162
   gurobi_opt.py2382380%3–675
   or_tools_opt.py2301195%103, 107, 296–305, 315, 319, 607, 611
TOTAL462370885% 

Tests Skipped Failures Errors Time
144 0 💤 0 ❌ 0 🔥 6m 14s ⏱️

Copy link
Contributor

github-actions bot commented Jan 15, 2025

Coverage

Coverage Report for Python 3.12
FileStmtsMissCoverMissing
choice_learn
   __init__.py20100% 
   tf_ops.py480100% 
choice_learn/basket_models
   shopper.py2808271%72, 76, 89–110, 127, 227, 295, 446, 500, 533, 686–696, 747, 964, 982, 1021, 1035, 1042, 1050–1081, 1116–1146, 1156–1178, 1195–1244
   trip_dataset.py1223472%52, 79, 121, 131, 148–161, 181, 225, 247, 257, 267, 297, 391, 405–423, 528–534
choice_learn/basket_models/utils
   permutation.py22195%35
choice_learn/data
   __init__.py30100% 
   choice_dataset.py6473395%198, 250, 283, 421, 463–464, 589, 724, 738, 840, 842, 937, 957–961, 1140, 1159–1161, 1179–1181, 1209, 1214, 1223, 1240, 1281, 1293, 1307, 1346, 1361, 1366, 1395, 1408, 1443–1444
   indexer.py2392390%20, 31, 45, 60–67, 202–204, 219–230, 265, 291, 577
   storage.py161696%22, 33, 51, 56, 61, 71
   store.py72720%3–275
choice_learn/datasets
   __init__.py40100% 
   base.py393499%39, 154–155, 715
   expedia.py1028319%37–301
   tafeng.py490100% 
choice_learn/datasets/data
   __init__.py00100% 
choice_learn/models
   __init__.py14286%15–16
   base_model.py2541295%144, 186, 283, 302, 342, 349, 378, 397, 428–429, 438–439
   baseline_models.py490100% 
   conditional_logit.py2362191%46, 49, 51, 82, 85, 88–92, 95–99, 133, 298, 335, 392, 467–473, 598, 632, 739, 743
   halo_mnl.py124298%186, 374
   latent_class_base_model.py2863986%55–61, 273–279, 288, 325–330, 497–500, 605, 624, 665–701, 715, 720, 751–752, 774–775, 869–870, 974
   latent_class_mnl.py62690%257–261, 296
   learning_mnl.py67396%157, 182, 188
   nested_logit.py2911296%55, 77, 160, 269, 351, 484, 530, 600, 679, 848, 900, 904
   reslogit.py132695%285, 360, 369, 374, 382, 432
   rumnet.py236399%748–751, 982
   simple_mnl.py139696%167, 275, 347, 355, 357, 359
   tastenet.py94397%142, 180, 188
choice_learn/toolbox
   __init__.py00100% 
   assortment_optimizer.py27678%28–30, 93–95, 160–162
   gurobi_opt.py2382380%3–675
   or_tools_opt.py2301195%103, 107, 296–305, 315, 319, 607, 611
TOTAL462370885% 

Tests Skipped Failures Errors Time
144 0 💤 0 ❌ 0 🔥 7m 39s ⏱️

Copy link
Collaborator

@VincentAuriau VincentAuriau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First round of comments, to be discussed :)

choice_learn/basket_models/base_basket.py Outdated Show resolved Hide resolved
choice_learn/basket_models/base_basket.py Outdated Show resolved Hide resolved
choice_learn/basket_models/base_basket.py Outdated Show resolved Hide resolved
choice_learn/basket_models/base_basket.py Outdated Show resolved Hide resolved
choice_learn/basket_models/base_basket.py Outdated Show resolved Hide resolved
choice_learn/basket_models/shopper.py Outdated Show resolved Hide resolved
choice_learn/basket_models/shopper.py Outdated Show resolved Hide resolved
choice_learn/basket_models/trip_dataset.py Outdated Show resolved Hide resolved
choice_learn/basket_models/utils/permutation.py Outdated Show resolved Hide resolved
choice_learn/models/base_model.py Show resolved Hide resolved
@VincentAuriau VincentAuriau linked an issue Jan 16, 2025 that may be closed by this pull request
choice_learn/basket_models/shopper.py Outdated Show resolved Hide resolved
choice_learn/basket_models/shopper.py Outdated Show resolved Hide resolved
choice_learn/basket_models/shopper.py Show resolved Hide resolved
choice_learn/basket_models/shopper.py Outdated Show resolved Hide resolved
choice_learn/basket_models/shopper.py Show resolved Hide resolved
choice_learn/basket_models/shopper.py Outdated Show resolved Hide resolved
choice_learn/basket_models/shopper.py Outdated Show resolved Hide resolved
choice_learn/basket_models/shopper.py Outdated Show resolved Hide resolved
choice_learn/basket_models/shopper.py Outdated Show resolved Hide resolved
choice_learn/basket_models/shopper.py Outdated Show resolved Hide resolved
Shape must be (n_items,)
"""
# Prevent unintended side effects from in-place modifications
availability_matrix_copy = availability_matrix.copy()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Je comprends que ce soit là, si on arrive à l'enlever c'est mieux =)

choice_learn/basket_models/shopper.py Outdated Show resolved Hide resolved
choice_learn/basket_models/shopper.py Outdated Show resolved Hide resolved
choice_learn/basket_models/shopper.py Outdated Show resolved Hide resolved
choice_learn/basket_models/trip_dataset.py Outdated Show resolved Hide resolved
class TripDataset:
"""Class for a dataset of trips."""

def __init__(self, trips: list[Trip], assortments: dict[int, np.ndarray]) -> None:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

les assortments pourraient être des FeaturesStorage -> parlons en :)

choice_learn/basket_models/trip_dataset.py Outdated Show resolved Hide resolved
choice_learn/basket_models/trip_dataset.py Outdated Show resolved Hide resolved
choice_learn/basket_models/trip_dataset.py Outdated Show resolved Hide resolved
choice_learn/basket_models/trip_dataset.py Outdated Show resolved Hide resolved
choice_learn/basket_models/trip_dataset.py Outdated Show resolved Hide resolved
choice_learn/basket_models/trip_dataset.py Outdated Show resolved Hide resolved


def from_csv(
train_file: str,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could it be a method of the TripDataset class ?

Copy link
Collaborator Author

@julesdesir julesdesir Jan 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then trip_preprocessing.py should be deleted?

There are only 3 functions in this file:

  • from_csv
  • csv_to_df and map_indexes (2 short functions which don't justify on their own the existence of trip_preprocesing.py and could be moved to the folder choice_learn/basket_models/utils if from_csv is moved to trip_dataset.py)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature Additional feature to be added
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ADD: SHOPPER model
2 participants