From 2b7943163df9dc9c351e0b6db08c0370e0098f33 Mon Sep 17 00:00:00 2001 From: Vincent Auriau Date: Thu, 31 Oct 2024 09:02:03 -0700 Subject: [PATCH] Add colab notebooks links (#175) * Add colab links to example notebooks Fixes #172 Add colab links and necessary requirements to example notebooks. * Add colab links to the top of each example notebook in the `notebooks` directory. * Add a cell that installs necessary requirements (`!pip install choice-learn`) in each notebook. * Fix minor formatting issues in some notebooks. --------- Co-authored-by: chicham --- README.md | 35 +- .../auxiliary_tools/assortment_example.ipynb | 31 +- notebooks/data/dataset_creation.ipynb | 299 ++++++++++++++---- notebooks/data/features_byID_examples.ipynb | 47 ++- .../introduction/1_introductive_example.ipynb | 18 +- notebooks/introduction/2_data_handling.ipynb | 255 ++------------- notebooks/introduction/3_model_clogit.ipynb | 25 +- .../introduction/4_model_customization.ipynb | 25 +- notebooks/models/latent_class_model.ipynb | 27 +- notebooks/models/learning_mnl.ipynb | 24 +- notebooks/models/logistic_regression.ipynb | 24 +- notebooks/models/nested_logit.ipynb | 23 +- notebooks/models/reslogit.ipynb | 24 +- notebooks/models/rumnet.ipynb | 24 +- notebooks/models/simple_mnl.ipynb | 27 +- notebooks/models/tastenet.ipynb | 24 +- 16 files changed, 582 insertions(+), 350 deletions(-) diff --git a/README.md b/README.md index 46b101fe..2a9e417e 100644 --- a/README.md +++ b/README.md @@ -70,32 +70,33 @@ If you are new to choice modeling, you can check this [resource](https://www.pub - Otherwise, **custom modeling** is made easy by subclassing the ChoiceModel class and specifying your own utility function. [[Example]](notebooks/introduction/4_model_customization.ipynb) *List of implemented & ready-to-use models:* -| Model | Example | Related Paper | *from choice_learn.models import* | Doc | -| ---------- | -------- | ------ | ------ | :---: | -| MNL | [notebook](notebooks/models/simple_mnl.ipynb) | | *SimpleMNL* | [#](https://artefactory.github.io/choice-learn/references/models/references_simple_mnl/) | -| Conditional Logit | [notebook](notebooks/introduction/3_model_clogit.ipynb) | Train et al. [[4]](#trident-references)              | *ConditionalLogit* | [#](https://artefactory.github.io/choice-learn/references/models/references_clogit/) | -| Nested Logit | [notebook](notebooks/models/nested_logit.ipynb) | McFadden [[10]](#trident-references) | *NestedLogit* | [#](https://artefactory.github.io/choice-learn/references/models/references_nested_logit/) | -| Latent Class MNL | [notebook](notebooks/models/latent_class_model.ipynb) | | *LatentClassConditionalLogit* | [#](LatentClassConditionalLogit) | +| Model | Example | Colab | Related Paper | *from choice_learn.models import* | Doc | +| ---------- | -------- | -------- | ------ | ------ | :---: | +| MNL | [notebook](notebooks/models/simple_mnl.ipynb) | [![Open In Colab](https://img.shields.io/badge/-grey?logo=googlecolab)](https://colab.research.google.com/github/artefactory/choice-learn/blob/main/notebooks/models/simple_mnl.ipynb) | | *SimpleMNL* | [#](https://artefactory.github.io/choice-learn/references/models/references_simple_mnl/) | +| Conditional Logit | [notebook](notebooks/introduction/3_model_clogit.ipynb) | [![Open In Colab](https://img.shields.io/badge/-grey?logo=googlecolab)](https://colab.research.google.com/github/artefactory/choice-learn/blob/main/notebooks/introduction/3_model_clogit.ipynb) | Train et al. [[4]](#trident-references)            | *ConditionalLogit* | [#](https://artefactory.github.io/choice-learn/references/models/references_clogit/) | +| Nested Logit | [notebook](notebooks/models/nested_logit.ipynb) | [![Open In Colab](https://img.shields.io/badge/-grey?logo=googlecolab)](https://colab.research.google.com/github/artefactory/choice-learn/blob/main/notebooks/models/nested_logit.ipynb) | McFadden [[10]](#trident-references) | *NestedLogit* | [#](https://artefactory.github.io/choice-learn/references/models/references_nested_logit/) | +| Latent Class MNL | [notebook](notebooks/models/latent_class_model.ipynb) | [![Open In Colab](https://img.shields.io/badge/-grey?logo=googlecolab)](https://colab.research.google.com/github/artefactory/choice-learn/blob/main/notebooks/models/latent_class_model.ipynb) | | *LatentClassConditionalLogit* | [#](LatentClassConditionalLogit) | -| NN-based Model | Example | Related Paper | *from choice_learn.models import* | Doc | -| ---------- | -------- | ------ | ------ | :---: | -| RUMnet| [notebook](notebooks/models/rumnet.ipynb) | Aouad and Désir [[1]](#trident-references) | *RUMnet* | [#](https://artefactory.github.io/choice-learn/references/models/references_rumnet/#choice_learn.models.rumnet.PaperRUMnet) | -| TasteNet | [notebook](notebooks/models/tastenet.ipynb) | Han et al. [[7]](#trident-references) | *TasteNet* | [#](https://artefactory.github.io/choice-learn/references/models/references_tastenet/) | -| Learning-MNL | [notebook](notebooks/models/learning_mnl.ipynb) | Sifringer et al. [[13]](#trident-references) | *LearningMNL* | [#](https://artefactory.github.io/choice-learn/references/models/references_learning_mnl/) | -| ResLogit | [notebook](notebooks/models/reslogit.ipynb) | Wong and Farooq [[12]](#trident-references) | *ResLogit* | [#](https://artefactory.github.io/choice-learn/references/models/references_reslogit/) | +| NN-based Model | Example | Colab | Related Paper | *from choice_learn.models import* | Doc | +| ---------- | -------- | ------ | ---- | ------ | :---: | +| RUMnet| [notebook](notebooks/models/rumnet.ipynb) | [![Open In Colab](https://img.shields.io/badge/-grey?logo=googlecolab)](https://colab.research.google.com/github/artefactory/choice-learn/blob/main/notebooks/models/rumnet.ipynb) |Aouad and Désir [[1]](#trident-references) | *RUMnet* | [#](https://artefactory.github.io/choice-learn/references/models/references_rumnet/#choice_learn.models.rumnet.PaperRUMnet) | +| TasteNet | [notebook](notebooks/models/tastenet.ipynb) | [![Open In Colab](https://img.shields.io/badge/-grey?logo=googlecolab)](https://colab.research.google.com/github/artefactory/choice-learn/blob/main/notebooks/models/tastenet.ipynb) |Han et al. [[7]](#trident-references) | *TasteNet* | [#](https://artefactory.github.io/choice-learn/references/models/references_tastenet/) | +| Learning-MNL | [notebook](notebooks/models/learning_mnl.ipynb) | [![Open In Colab](https://img.shields.io/badge/-grey?logo=googlecolab)](https://colab.research.google.com/github/artefactory/choice-learn/blob/main/notebooks/models/learning_mnl.ipynb) |Sifringer et al. [[13]](#trident-references) | *LearningMNL* | [#](https://artefactory.github.io/choice-learn/references/models/references_learning_mnl/) | +| ResLogit | [notebook](notebooks/models/reslogit.ipynb) | [![Open In Colab](https://img.shields.io/badge/-grey?logo=googlecolab)](https://colab.research.google.com/github/artefactory/choice-learn/blob/main/notebooks/models/reslogit.ipynb) |Wong and Farooq [[12]](#trident-references) | *ResLogit* | [#](https://artefactory.github.io/choice-learn/references/models/references_reslogit/) | ### Auxiliary tools Algorithms leveraging choice models are integrated within the library: -- Assortment & Pricing optimization algorithms [[Example]](notebooks/auxiliary_tools/assortment_example.ipynb) [[8]](#trident-references) +- Assortment & Pricing optimization algorithms [[Example]](notebooks/auxiliary_tools/assortment_example.ipynb) [[8]](#trident-references) [![Open In Colab](https://img.shields.io/badge/-grey?logo=googlecolab)](https://colab.research.google.com/github/artefactory/choice-learn/blob/main/notebooks/auxiliary_tools/assortment_example.ipynb) ## :trident: Getting Started You can find the following tutorials to help you getting started with the package: -- Generic and simple introduction [[notebook]](notebooks/introduction/1_introductive_example.ipynb)[[doc]](https://expert-dollop-1wemk8l.pages.github.io/notebooks/introduction/1_introductive_example/) -- Detailed explanations of data handling depending on the data format [[noteboook]](notebooks/introduction/2_data_handling.ipynb)[[doc]](https://expert-dollop-1wemk8l.pages.github.io/notebooks/introduction/2_data_handling/) -- A detailed example of conditional logit estimation [[notebook]](notebooks/introduction/3_model_clogit.ipynb)[[doc]](https://expert-dollop-1wemk8l.pages.github.io/notebooks/introduction/3_model_clogit/) -- Introduction to custom modeling and more complex parametrization [[notebook]](notebooks/introduction/4_model_customization.ipynb)[[doc]](https://expert-dollop-1wemk8l.pages.github.io/notebooks/introduction/4_model_customization/) +- Generic and simple introduction [[notebook]](notebooks/introduction/1_introductive_example.ipynb)[[doc]](https://expert-dollop-1wemk8l.pages.github.io/notebooks/introduction/1_introductive_example/) [![Open In Colab](https://img.shields.io/badge/-grey?logo=googlecolab +)](https://colab.research.google.com/github/artefactory/choice-learn/blob/main/notebooks/introduction/1_introductive_example.ipynb) +- Detailed explanations of data handling depending on the data format [[noteboook]](notebooks/introduction/2_data_handling.ipynb)[[doc]](https://expert-dollop-1wemk8l.pages.github.io/notebooks/introduction/2_data_handling/) [![Open In Colab](https://img.shields.io/badge/-grey?logo=googlecolab)](https://colab.research.google.com/github/artefactory/choice-learn/blob/main/notebooks/introduction/2_data_handling.ipynb) +- A detailed example of conditional logit estimation [[notebook]](notebooks/introduction/3_model_clogit.ipynb)[[doc]](https://expert-dollop-1wemk8l.pages.github.io/notebooks/introduction/3_model_clogit/) [![Open In Colab](https://img.shields.io/badge/-grey?logo=googlecolab)](https://colab.research.google.com/github/artefactory/choice-learn/blob/main/notebooks/introduction/3_model_clogit.ipynb) +- Introduction to custom modeling and more complex parametrization [[notebook]](notebooks/introduction/4_model_customization.ipynb)[[doc]](https://expert-dollop-1wemk8l.pages.github.io/notebooks/introduction/4_model_customization/) [![Open In Colab](https://img.shields.io/badge/-grey?logo=googlecolab)](https://colab.research.google.com/github/artefactory/choice-learn/blob/main/notebooks/introduction/4_model_customization.ipynb) - All models and algorithms have a companion example in the notebook [directory](./notebooks/) ## :trident: Installation diff --git a/notebooks/auxiliary_tools/assortment_example.ipynb b/notebooks/auxiliary_tools/assortment_example.ipynb index 57b5dfbb..8ecf913f 100644 --- a/notebooks/auxiliary_tools/assortment_example.ipynb +++ b/notebooks/auxiliary_tools/assortment_example.ipynb @@ -16,7 +16,29 @@ " - [Choice-Learn's AssortmentOptimizer](#choice-learns-assortmentoptimizer)\n", " - [Assortment with Latent Class models](#latent-class-assortment-optimizer)\n", " - [Adding Capacity Constraints](#adding-capacity-constraints)\n", - "- [Pricing and assortment](#pricing-and-assortment-optimization)" + "- [Pricing and assortment](#pricing-and-assortment-optimization)\n", + "\n", + "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/artefactory/choice-learn/blob/main/notebooks/auxiliary_tools/assortment_example.ipynb)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Install necessary requirements\n", + "\n", + "# If you run this notebook on Google Colab, or in standalone mode, you need to install the required packages.\n", + "# Uncomment the following lines:\n", + "\n", + "# !pip install choice-learn\n", + "\n", + "# If you run the notebook within the GitHub repository, you need to run the following lines, that can skipped otherwise:\n", + "import os\n", + "import sys\n", + "\n", + "sys.path.append(\"../../\")" ] }, { @@ -30,9 +52,6 @@ "# Remove GPU use\n", "os.environ[\"CUDA_VISIBLE_DEVICES\"] = \"\"\n", "\n", - "import sys\n", - "sys.path.append(\"../../\")\n", - "\n", "import numpy as np" ] }, @@ -923,6 +942,10 @@ } ], "metadata": { + "colab": { + "name": "Assortment Example", + "provenance": [] + }, "kernelspec": { "display_name": "tf_env", "language": "python", diff --git a/notebooks/data/dataset_creation.ipynb b/notebooks/data/dataset_creation.ipynb index da977bbd..08dd7e3c 100644 --- a/notebooks/data/dataset_creation.ipynb +++ b/notebooks/data/dataset_creation.ipynb @@ -11,7 +11,9 @@ "- [From a single long format DataFrame](#from-a-single-long-format-dataframe)\n", "- [From a single wide format DataFrame](#from-a-single-wide-format-dataframe)\n", "- [From several DataFrames](#from-several-dataframes)\n", - "- [From several np.ndarrays](#from-several-npndarrays)" + "- [From several np.ndarrays](#from-several-npndarrays)\n", + "\n", + "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/artefactory/choice-learn/blob/main/notebooks/data/dataset_creation.ipynb)" ] }, { @@ -20,13 +22,26 @@ "metadata": {}, "outputs": [], "source": [ - "import os\n", - "import sys\n", - "from pathlib import Path\n", + "# Install necessary requirements\n", "\n", + "# If you run this notebook on Google Colab, or in standalone mode, you need to install the required packages.\n", + "# Uncomment the following lines:\n", "\n", - "sys.path.append(\"../../\")\n", + "# !pip install choice-learn\n", + "\n", + "# If you run the notebook within the GitHub repository, you need to run the following lines, that can skipped otherwise:\n", + "import os\n", + "import sys\n", "\n", + "sys.path.append(\"../../\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ "import numpy as np\n", "import pandas as pd\n", "\n", @@ -69,7 +84,6 @@ " \n", " \n", " \n", - " Unnamed: 0\n", " case\n", " alt\n", " choice\n", @@ -87,7 +101,6 @@ " \n", " 0\n", " 1\n", - " 1\n", " train\n", " 0\n", " 83\n", @@ -101,7 +114,6 @@ " \n", " \n", " 1\n", - " 2\n", " 1\n", " car\n", " 1\n", @@ -116,7 +128,6 @@ " \n", " \n", " 2\n", - " 3\n", " 2\n", " train\n", " 0\n", @@ -131,7 +142,6 @@ " \n", " \n", " 3\n", - " 4\n", " 2\n", " car\n", " 1\n", @@ -146,7 +156,6 @@ " \n", " \n", " 4\n", - " 5\n", " 3\n", " train\n", " 0\n", @@ -164,19 +173,12 @@ "" ], "text/plain": [ - " Unnamed: 0 case alt choice dist cost ivt ovt freq income \\\n", - "0 1 1 train 0 83 28.25 50 66 4 45.0 \n", - "1 2 1 car 1 83 15.77 61 0 0 45.0 \n", - "2 3 2 train 0 83 28.25 50 66 4 25.0 \n", - "3 4 2 car 1 83 15.77 61 0 0 25.0 \n", - "4 5 3 train 0 83 28.25 50 66 4 70.0 \n", - "\n", - " urban noalt \n", - "0 0 2 \n", - "1 0 2 \n", - "2 0 2 \n", - "3 0 2 \n", - "4 0 2 " + " case alt choice dist cost ivt ovt freq income urban noalt\n", + "0 1 train 0 83 28.25 50 66 4 45.0 0 2\n", + "1 1 car 1 83 15.77 61 0 0 45.0 0 2\n", + "2 2 train 0 83 28.25 50 66 4 25.0 0 2\n", + "3 2 car 1 83 15.77 61 0 0 25.0 0 2\n", + "4 3 train 0 83 28.25 50 66 4 70.0 0 2" ] }, "execution_count": null, @@ -228,7 +230,7 @@ "\n", "\n", " Items Features by Choice:\n", - " 4 items features \n", + "4 items features \n", " with names: (['freq', 'cost', 'ivt', 'ovt'],)\n", "%=====================================================================%\n", "\n" @@ -283,7 +285,6 @@ " \n", " \n", " \n", - " Unnamed: 0\n", " case\n", " alt\n", " choice\n", @@ -301,7 +302,6 @@ " \n", " 0\n", " 1\n", - " 1\n", " train\n", " car\n", " 83\n", @@ -315,7 +315,6 @@ " \n", " \n", " 1\n", - " 2\n", " 1\n", " car\n", " car\n", @@ -330,7 +329,6 @@ " \n", " \n", " 2\n", - " 3\n", " 2\n", " train\n", " car\n", @@ -345,7 +343,6 @@ " \n", " \n", " 3\n", - " 4\n", " 2\n", " car\n", " car\n", @@ -360,7 +357,6 @@ " \n", " \n", " 4\n", - " 5\n", " 3\n", " train\n", " car\n", @@ -378,19 +374,12 @@ "" ], "text/plain": [ - " Unnamed: 0 case alt choice dist cost ivt ovt freq income urban \\\n", - "0 1 1 train car 83 28.25 50 66 4 45.0 0 \n", - "1 2 1 car car 83 15.77 61 0 0 45.0 0 \n", - "2 3 2 train car 83 28.25 50 66 4 25.0 0 \n", - "3 4 2 car car 83 15.77 61 0 0 25.0 0 \n", - "4 5 3 train car 83 28.25 50 66 4 70.0 0 \n", - "\n", - " noalt \n", - "0 2 \n", - "1 2 \n", - "2 2 \n", - "3 2 \n", - "4 2 " + " case alt choice dist cost ivt ovt freq income urban noalt\n", + "0 1 train car 83 28.25 50 66 4 45.0 0 2\n", + "1 1 car car 83 15.77 61 0 0 45.0 0 2\n", + "2 2 train car 83 28.25 50 66 4 25.0 0 2\n", + "3 2 car car 83 15.77 61 0 0 25.0 0 2\n", + "4 3 train car 83 28.25 50 66 4 70.0 0 2" ] }, "execution_count": null, @@ -434,7 +423,7 @@ "\n", "\n", " Items Features by Choice:\n", - " 4 items features \n", + "4 items features \n", " with names: (['freq', 'cost', 'ivt', 'ovt'],)\n", "%=====================================================================%\n", "\n" @@ -466,8 +455,210 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, - "outputs": [], + "metadata": { + "keep_output": true + }, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
GROUPSURVEYSPIDPURPOSEFIRSTTICKETWHOLUGGAGEAGE...TRAIN_COTRAIN_HESM_TTSM_COSM_HESM_SEATSCAR_TTCAR_COCHOICECAR_HE
02011101103...4812063522001176510.0
12011101103...483060491001178410.0
22011101103...486067583001175210.0
32011101103...40306352200725210.0
42011101103...36606342200908410.0
\n", + "

5 rows × 29 columns

\n", + "
" + ], + "text/plain": [ + " GROUP SURVEY SP ID PURPOSE FIRST TICKET WHO LUGGAGE AGE ... \\\n", + "0 2 0 1 1 1 0 1 1 0 3 ... \n", + "1 2 0 1 1 1 0 1 1 0 3 ... \n", + "2 2 0 1 1 1 0 1 1 0 3 ... \n", + "3 2 0 1 1 1 0 1 1 0 3 ... \n", + "4 2 0 1 1 1 0 1 1 0 3 ... \n", + "\n", + " TRAIN_CO TRAIN_HE SM_TT SM_CO SM_HE SM_SEATS CAR_TT CAR_CO CHOICE \\\n", + "0 48 120 63 52 20 0 117 65 1 \n", + "1 48 30 60 49 10 0 117 84 1 \n", + "2 48 60 67 58 30 0 117 52 1 \n", + "3 40 30 63 52 20 0 72 52 1 \n", + "4 36 60 63 42 20 0 90 84 1 \n", + "\n", + " CAR_HE \n", + "0 0.0 \n", + "1 0.0 \n", + "2 0.0 \n", + "3 0.0 \n", + "4 0.0 \n", + "\n", + "[5 rows x 29 columns]" + ] + }, + "execution_count": null, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "from choice_learn.datasets import load_swissmetro\n", "\n", @@ -864,7 +1055,7 @@ "\n", "\n", " Items Features by Choice:\n", - " 5 items features \n", + "5 items features \n", " with names: (Index(['cost', 'freq', 'is_public', 'ivt', 'ovt'], dtype='object'),)\n", "%=====================================================================%\n", "\n" @@ -896,9 +1087,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "keep_output": true - }, + "metadata": {}, "outputs": [], "source": [ "shared_features, items_features, available_items_by_choice, choices =\\\n", @@ -972,7 +1161,7 @@ "\n", "\n", " Items Features by Choice:\n", - " 4 items features \n", + "4 items features \n", " with names: (['freq', 'cost', 'ivt', 'ovt'],)\n", "%=====================================================================%\n", "\n" @@ -1000,6 +1189,10 @@ } ], "metadata": { + "colab": { + "name": "Dataset Creation", + "provenance": [] + }, "kernelspec": { "display_name": "tf_env", "language": "python", @@ -1015,7 +1208,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.4" + "version": "3.8.18" } }, "nbformat": 4, diff --git a/notebooks/data/features_byID_examples.ipynb b/notebooks/data/features_byID_examples.ipynb index ffaa50c6..2be597b7 100644 --- a/notebooks/data/features_byID_examples.ipynb +++ b/notebooks/data/features_byID_examples.ipynb @@ -25,7 +25,9 @@ "\n", "- [Example with the SwissMetro](#example-with-the-swissmetro-dataset)\n", "\n", - "- [Link to another example: Expedia Dataset](#link-to-another-example)" + "- [Link to another example: Expedia Dataset](#link-to-another-example)\n", + "\n", + "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/artefactory/choice-learn/blob/main/notebooks/data/features_byID_examples.ipynb)" ] }, { @@ -34,14 +36,29 @@ "metadata": {}, "outputs": [], "source": [ - "import os\n", + "# Install necessary requirements\n", "\n", - "# Remove GPU use\n", - "os.environ[\"CUDA_VISIBLE_DEVICES\"] = \"\"\n", + "# If you run this notebook on Google Colab, or in standalone mode, you need to install the required packages.\n", + "# Uncomment the following lines:\n", + "\n", + "# !pip install choice-learn\n", "\n", + "# If you run the notebook within the GitHub repository, you need to run the following lines, that can skipped otherwise:\n", + "import os\n", "import sys\n", "\n", - "sys.path.append(\"../../\")\n", + "sys.path.append(\"../../\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import os\n", + "# Remove GPU use\n", + "os.environ[\"CUDA_VISIBLE_DEVICES\"] = \"\"\n", "\n", "import numpy as np\n", "import pandas as pd" @@ -309,9 +326,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "keep_output": true - }, + "metadata": {}, "outputs": [], "source": [ "ids = [0, 1, 2, 3, 4]\n", @@ -621,7 +636,7 @@ " PURPOSE\n", " FIRST\n", " TICKET\n", - " WHO\n", + " WHO\n", " LUGGAGE\n", " AGE\n", " ...\n", @@ -663,7 +678,7 @@ " 0.0\n", " \n", " \n", - " 1\n", + " 1\n", " 2\n", " 0\n", " 1\n", @@ -687,7 +702,7 @@ " 0.0\n", " \n", " \n", - " 2\n", + " 2\n", " 2\n", " 0\n", " 1\n", @@ -711,7 +726,7 @@ " 0.0\n", " \n", " \n", - " 3\n", + " 3\n", " 2\n", " 0\n", " 1\n", @@ -735,7 +750,7 @@ " 0.0\n", " \n", " \n", - " 4\n", + " 4\n", " 2\n", " 0\n", " 1\n", @@ -907,6 +922,10 @@ } ], "metadata": { + "colab": { + "name": "Features by ID Examples", + "provenance": [] + }, "kernelspec": { "display_name": "tf_env", "language": "python", @@ -922,7 +941,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.4" + "version": "3.8.18" } }, "nbformat": 4, diff --git a/notebooks/introduction/1_introductive_example.ipynb b/notebooks/introduction/1_introductive_example.ipynb index e470902e..bc55099d 100644 --- a/notebooks/introduction/1_introductive_example.ipynb +++ b/notebooks/introduction/1_introductive_example.ipynb @@ -4,7 +4,11 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "       " + "

\n", + " Introduction Notebook \n", + "

\n", + "\n", + "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/artefactory/choice-learn/blob/main/notebooks/introduction/1_introductive_example.ipynb)" ] }, { @@ -13,6 +17,14 @@ "metadata": {}, "outputs": [], "source": [ + "# Install necessary requirements\n", + "\n", + "# If you run this notebook on Google Colab, or in standalone mode, you need to install the required packages.\n", + "# Uncomment the following lines:\n", + "\n", + "# !pip install choice-learn\n", + "\n", + "# If you run the notebook within the GitHub repository, you need to run the following lines, that can skipped otherwise:\n", "import os\n", "import sys\n", "\n", @@ -348,6 +360,10 @@ } ], "metadata": { + "colab": { + "name": "Introductive Example", + "provenance": [] + }, "kernelspec": { "display_name": "tf_env", "language": "python", diff --git a/notebooks/introduction/2_data_handling.ipynb b/notebooks/introduction/2_data_handling.ipynb index 12bb404f..7fb91043 100644 --- a/notebooks/introduction/2_data_handling.ipynb +++ b/notebooks/introduction/2_data_handling.ipynb @@ -4,7 +4,9 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "# Introduction to choice-learn's data management" + "# Introduction to choice-learn's data management\n", + "\n", + "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/artefactory/choice-learn/blob/main/notebooks/introduction/2_data_handling.ipynb)" ] }, { @@ -13,11 +15,26 @@ "metadata": {}, "outputs": [], "source": [ + "# Install necessary requirements\n", + "\n", + "# If you run this notebook on Google Colab, or in standalone mode, you need to install the required packages.\n", + "# Uncomment the following lines:\n", + "\n", + "# !pip install choice-learn\n", + "\n", + "# If you run the notebook within the GitHub repository, you need to run the following lines, that can skipped otherwise:\n", "import os\n", "import sys\n", "\n", - "sys.path.append(\"../../\")\n", - "\n", + "sys.path.append(\"../../\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ "import numpy as np\n", "import pandas as pd" ] @@ -1136,7 +1153,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "keep_output": true + }, "outputs": [], "source": [ "# Creation of the ChoiceDataset\n", @@ -1150,22 +1169,8 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "keep_output": true - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Batch Shared Items Features: [[100 250]\n", - " [150 500]\n", - " [ 80 100]]\n", - "Batch Items Features: None\n", - "Batch Choice: [1 2 0]\n" - ] - } - ], + "metadata": {}, + "outputs": [], "source": [ "# And now it's ready\n", "batch = storage_dataset.batch[[1, 2, 3]]\n", @@ -1227,210 +1232,8 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "keep_output": true - }, - "outputs": [ - { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
GROUPSURVEYSPIDPURPOSEFIRSTTICKETWHOLUGGAGEAGE...TRAIN_COTRAIN_HESM_TTSM_COSM_HESM_SEATSCAR_TTCAR_COCHOICECAR_HE
02011101103...4812063522001176510.0
12011101103...483060491001178410.0
22011101103...486067583001175210.0
32011101103...40306352200725210.0
42011101103...36606342200908410.0
\n", - "

5 rows × 29 columns

\n", - "
" - ], - "text/plain": [ - " GROUP SURVEY SP ID PURPOSE FIRST TICKET WHO LUGGAGE AGE ... \\\n", - "0 2 0 1 1 1 0 1 1 0 3 ... \n", - "1 2 0 1 1 1 0 1 1 0 3 ... \n", - "2 2 0 1 1 1 0 1 1 0 3 ... \n", - "3 2 0 1 1 1 0 1 1 0 3 ... \n", - "4 2 0 1 1 1 0 1 1 0 3 ... \n", - "\n", - " TRAIN_CO TRAIN_HE SM_TT SM_CO SM_HE SM_SEATS CAR_TT CAR_CO CHOICE \\\n", - "0 48 120 63 52 20 0 117 65 1 \n", - "1 48 30 60 49 10 0 117 84 1 \n", - "2 48 60 67 58 30 0 117 52 1 \n", - "3 40 30 63 52 20 0 72 52 1 \n", - "4 36 60 63 42 20 0 90 84 1 \n", - "\n", - " CAR_HE \n", - "0 0.0 \n", - "1 0.0 \n", - "2 0.0 \n", - "3 0.0 \n", - "4 0.0 \n", - "\n", - "[5 rows x 29 columns]" - ] - }, - "execution_count": null, - "metadata": {}, - "output_type": "execute_result" - } - ], + "metadata": {}, + "outputs": [], "source": [ "swissmetro_df = load_swissmetro(as_frame=True)\n", "swissmetro_df.head()" @@ -1455,6 +1258,10 @@ } ], "metadata": { + "colab": { + "name": "Introduction to choice-learn's data management", + "provenance": [] + }, "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", diff --git a/notebooks/introduction/3_model_clogit.ipynb b/notebooks/introduction/3_model_clogit.ipynb index 4ee5daa2..711ec7ff 100644 --- a/notebooks/introduction/3_model_clogit.ipynb +++ b/notebooks/introduction/3_model_clogit.ipynb @@ -4,7 +4,9 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "# Introduction to choice-learn's modelling" + "# Introduction to choice-learn's modelling\n", + "\n", + "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/artefactory/choice-learn/blob/main/notebooks/introduction/3_model_clogit.ipynb)" ] }, { @@ -13,13 +15,28 @@ "metadata": {}, "outputs": [], "source": [ - "import os\n", + "# Install necessary requirements\n", "\n", - "os.environ[\"CUDA_VISIBLE_DEVICES\"] = \"\"\n", + "# If you run this notebook on Google Colab, or in standalone mode, you need to install the required packages.\n", + "# Uncomment the following lines:\n", + "\n", + "# !pip install choice-learn\n", "\n", + "# If you run the notebook within the GitHub repository, you need to run the following lines, that can skipped otherwise:\n", + "import os\n", "import sys\n", "\n", - "sys.path.append(\"../../\")\n", + "sys.path.append(\"../../\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import os\n", + "os.environ[\"CUDA_VISIBLE_DEVICES\"] = \"\"\n", "\n", "import numpy as np\n", "import pandas as pd\n", diff --git a/notebooks/introduction/4_model_customization.ipynb b/notebooks/introduction/4_model_customization.ipynb index 5f03b8b0..2c76237f 100644 --- a/notebooks/introduction/4_model_customization.ipynb +++ b/notebooks/introduction/4_model_customization.ipynb @@ -6,21 +6,38 @@ "metadata": {}, "outputs": [], "source": [ - "import os\n", + "# Install necessary requirements\n", "\n", - "# Remove GPU use\n", - "os.environ[\"CUDA_VISIBLE_DEVICES\"] = \"\"\n", + "# If you run this notebook on Google Colab, or in standalone mode, you need to install the required packages.\n", + "# Uncomment the following lines:\n", "\n", + "# !pip install choice-learn\n", + "\n", + "# If you run the notebook within the GitHub repository, you need to run the following lines, that can skipped otherwise:\n", + "import os\n", "import sys\n", "\n", "sys.path.append(\"../../\")" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import os\n", + "# Remove GPU use\n", + "os.environ[\"CUDA_VISIBLE_DEVICES\"] = \"\"" + ] + }, { "cell_type": "markdown", "metadata": {}, "source": [ - "# Introduction to customization" + "# Introduction to customization\n", + "\n", + "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/artefactory/choice-learn/blob/main/notebooks/introduction/4_model_customization.ipynb)" ] }, { diff --git a/notebooks/models/latent_class_model.ipynb b/notebooks/models/latent_class_model.ipynb index db2643bd..5feea829 100644 --- a/notebooks/models/latent_class_model.ipynb +++ b/notebooks/models/latent_class_model.ipynb @@ -4,7 +4,9 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "# Example of use of Latent Class MNL" + "# Example of use of Latent Class MNL\n", + "\n", + "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/artefactory/choice-learn/blob/main/notebooks/models/latent_class_model.ipynb)" ] }, { @@ -13,14 +15,29 @@ "metadata": {}, "outputs": [], "source": [ - "import os\n", + "# Install necessary requirements\n", "\n", - "os.environ[\"CUDA_VISIBLE_DEVICES\"] = \"\"\n", + "# If you run this notebook on Google Colab, or in standalone mode, you need to install the required packages.\n", + "# Uncomment the following lines:\n", + "\n", + "# !pip install choice-learn\n", "\n", + "# If you run the notebook within the GitHub repository, you need to run the following lines, that can skipped otherwise:\n", + "import os\n", "import sys\n", - "from pathlib import Path\n", "\n", - "sys.path.append(\"../../\")\n", + "sys.path.append(\"../../\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import os\n", + "\n", + "os.environ[\"CUDA_VISIBLE_DEVICES\"] = \"\"\n", "\n", "import numpy as np\n", "import pandas as pd\n", diff --git a/notebooks/models/learning_mnl.ipynb b/notebooks/models/learning_mnl.ipynb index 46ab946f..af280a0b 100644 --- a/notebooks/models/learning_mnl.ipynb +++ b/notebooks/models/learning_mnl.ipynb @@ -6,6 +6,8 @@ "source": [ "# The Learning-MNL model\n", "\n", + "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/artefactory/choice-learn/blob/main/notebooks/models/learning_mnl.ipynb)\n", + "\n", "In this notebook we use choice-learn implementation of the L-MNL model (from the paper Enhance Discrete Choice Models with Representation Learning) to obtain the same results as presented by the authors." ] }, @@ -15,13 +17,29 @@ "metadata": {}, "outputs": [], "source": [ - "import os\n", + "# Install necessary requirements\n", "\n", - "os.environ[\"CUDA_VISIBLE_DEVICES\"] = \"\"\n", + "# If you run this notebook on Google Colab, or in standalone mode, you need to install the required packages.\n", + "# Uncomment the following lines:\n", + "\n", + "# !pip install choice-learn\n", "\n", + "# If you run the notebook within the GitHub repository, you need to run the following lines, that can skipped otherwise:\n", + "import os\n", "import sys\n", "\n", - "sys.path.append(\"../../\")\n", + "sys.path.append(\"../../\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import os\n", + "\n", + "os.environ[\"CUDA_VISIBLE_DEVICES\"] = \"\"\n", "\n", "import numpy as np\n", "import pandas as pd" diff --git a/notebooks/models/logistic_regression.ipynb b/notebooks/models/logistic_regression.ipynb index 63cef045..23b5ed10 100644 --- a/notebooks/models/logistic_regression.ipynb +++ b/notebooks/models/logistic_regression.ipynb @@ -6,6 +6,8 @@ "source": [ "# Logistic Regression: 3-class Classifier\n", "\n", + "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/artefactory/choice-learn/blob/main/notebooks/models/logistic_regression.ipynb)\n", + "\n", "The Conditional MNL is a generalization of the multi-class Logistic Regression.\n", "Here, we recreate the scikit-learn tutorial that can be found [here](https://scikit-learn.org/stable/auto_examples/linear_model/plot_iris_logistic.html#sphx-glr-auto-examples-linear-model-plot-iris-logistic-py)." ] @@ -16,14 +18,30 @@ "metadata": {}, "outputs": [], "source": [ + "# Install necessary requirements\n", + "\n", + "# If you run this notebook on Google Colab, or in standalone mode, you need to install the required packages.\n", + "# Uncomment the following lines:\n", + "\n", + "# !pip install choice-learn\n", + "\n", + "# If you run the notebook within the GitHub repository, you need to run the following lines, that can skipped otherwise:\n", "import os\n", + "import sys\n", "\n", + "sys.path.append(\"../../\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import os\n", "# Remove GPU use\n", "os.environ[\"CUDA_VISIBLE_DEVICES\"] = \"\"\n", "\n", - "import sys\n", - "\n", - "sys.path.append(\"../../\")\n", "\n", "import matplotlib.pyplot as plt\n", "import numpy as np\n", diff --git a/notebooks/models/nested_logit.ipynb b/notebooks/models/nested_logit.ipynb index 614f755a..c07553b4 100644 --- a/notebooks/models/nested_logit.ipynb +++ b/notebooks/models/nested_logit.ipynb @@ -6,6 +6,7 @@ "source": [ "# The Nested Logit Model\n", "\n", + "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/artefactory/choice-learn/blob/main/notebooks/models/nested_logit.ipynb)\n", "\n", "The Nested Logit model considers sub-groups of alternatives totally substitutables, called 'nests'. The general idea is that a customer might choose its transportation mode between publics transport and its private car. And then, if he decides to use public transportations the customer chooses between taking the train or the bus.\\\n", "The classical Conditional Logit does not account for such decision process. Hence the introduction of the Nested Logit. More detailed information are available [here](https://cran.r-project.org/web/packages/mlogit/vignettes/c4.relaxiid.html#:~:text=The%20nested%20logit%20model&text=It%20is%20a%20generalization%20of,different%20nests%20are%20still%20uncorrelated.).\n", @@ -30,13 +31,29 @@ "metadata": {}, "outputs": [], "source": [ - "import os\n", + "# Install necessary requirements\n", "\n", - "os.environ[\"CUDA_VISIBLE_DEVICES\"] = \"\"\n", + "# If you run this notebook on Google Colab, or in standalone mode, you need to install the required packages.\n", + "# Uncomment the following lines:\n", "\n", + "# !pip install choice-learn\n", + "\n", + "# If you run the notebook within the GitHub repository, you need to run the following lines, that can skipped otherwise:\n", + "import os\n", "import sys\n", "\n", - "sys.path.append(\"../../\")\n", + "sys.path.append(\"../../\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import os\n", + "os.environ[\"CUDA_VISIBLE_DEVICES\"] = \"\"\n", + "\n", "\n", "import numpy as np\n", "import pandas as pd" diff --git a/notebooks/models/reslogit.ipynb b/notebooks/models/reslogit.ipynb index 1bdd167d..ea23ac8f 100644 --- a/notebooks/models/reslogit.ipynb +++ b/notebooks/models/reslogit.ipynb @@ -6,6 +6,8 @@ "source": [ "## Introduction to modelling with ResLogit\n", "\n", + "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/artefactory/choice-learn/blob/main/notebooks/models/reslogit.ipynb)\n", + "\n", "We use the Swissmetro dataset to demonstrate how to use the ResLogit model [1]. " ] }, @@ -15,15 +17,29 @@ "metadata": {}, "outputs": [], "source": [ - "import os\n", + "# Install necessary requirements\n", "\n", - "# Remove/Add GPU use\n", - "os.environ[\"CUDA_VISIBLE_DEVICES\"] = \"1\"\n", + "# If you run this notebook on Google Colab, or in standalone mode, you need to install the required packages.\n", + "# Uncomment the following lines:\n", "\n", + "# !pip install choice-learn\n", "\n", + "# If you run the notebook within the GitHub repository, you need to run the following lines, that can skipped otherwise:\n", + "import os\n", "import sys\n", "\n", - "sys.path.append(\"../../\")\n", + "sys.path.append(\"../../\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import os\n", + "# Remove/Add GPU use\n", + "os.environ[\"CUDA_VISIBLE_DEVICES\"] = \"1\"\n", "\n", "import timeit\n", "import matplotlib.pyplot as plt\n", diff --git a/notebooks/models/rumnet.ipynb b/notebooks/models/rumnet.ipynb index 919a4c9a..f509e99c 100644 --- a/notebooks/models/rumnet.ipynb +++ b/notebooks/models/rumnet.ipynb @@ -6,6 +6,8 @@ "source": [ "## Introduction to modelling with RUMnet\n", "\n", + "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/artefactory/choice-learn/blob/main/notebooks/models/rumnet.ipynb)\n", + "\n", "We reproduce in this notebook the results of the paper Representing Random Utility Choice Models with Neural Networks on the SwissMetro dataset." ] }, @@ -15,15 +17,29 @@ "metadata": {}, "outputs": [], "source": [ - "import os\n", + "# Install necessary requirements\n", "\n", - "# Remove/Add GPU use\n", - "os.environ[\"CUDA_VISIBLE_DEVICES\"] = \"1\"\n", + "# If you run this notebook on Google Colab, or in standalone mode, you need to install the required packages.\n", + "# Uncomment the following lines:\n", "\n", + "# !pip install choice-learn\n", "\n", + "# If you run the notebook within the GitHub repository, you need to run the following lines, that can skipped otherwise:\n", + "import os\n", "import sys\n", "\n", - "sys.path.append(\"../../\")\n", + "sys.path.append(\"../../\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import os\n", + "# Remove/Add GPU use\n", + "os.environ[\"CUDA_VISIBLE_DEVICES\"] = \"1\"\n", "\n", "import matplotlib.pyplot as plt\n", "import numpy as np\n", diff --git a/notebooks/models/simple_mnl.ipynb b/notebooks/models/simple_mnl.ipynb index ebdfca9d..387f7911 100644 --- a/notebooks/models/simple_mnl.ipynb +++ b/notebooks/models/simple_mnl.ipynb @@ -4,7 +4,9 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "# Simple MNL" + "# Simple MultiNomial Model\n", + "\n", + "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/artefactory/choice-learn/blob/main/notebooks/models/simple_mnl.ipynb)" ] }, { @@ -13,14 +15,29 @@ "metadata": {}, "outputs": [], "source": [ - "import os\n", + "# Install necessary requirements\n", "\n", - "# Remove GPU use\n", - "os.environ[\"CUDA_VISIBLE_DEVICES\"] = \"\"\n", + "# If you run this notebook on Google Colab, or in standalone mode, you need to install the required packages.\n", + "# Uncomment the following lines:\n", + "\n", + "# !pip install choice-learn\n", "\n", + "# If you run the notebook within the GitHub repository, you need to run the following lines, that can skipped otherwise:\n", + "import os\n", "import sys\n", "\n", - "sys.path.append(\"../../\")\n", + "sys.path.append(\"../../\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import os\n", + "# Remove GPU use\n", + "os.environ[\"CUDA_VISIBLE_DEVICES\"] = \"\"\n", "\n", "import numpy as np\n", "\n", diff --git a/notebooks/models/tastenet.ipynb b/notebooks/models/tastenet.ipynb index 7d942769..a5cd6087 100644 --- a/notebooks/models/tastenet.ipynb +++ b/notebooks/models/tastenet.ipynb @@ -5,6 +5,9 @@ "metadata": {}, "source": [ "# TasteNet\n", + "\n", + "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/artefactory/choice-learn/blob/main/notebooks/models/tastenet.ipynb)\n", + "\n", "The TasteNet model, developped in [1] is available in Choice-Learn. Here is a small example on how it can be used.\\\n", "Following the paper, we will use it on the SwissMetro [2] dataset.\n", "\n", @@ -22,11 +25,28 @@ "metadata": {}, "outputs": [], "source": [ + "# Install necessary requirements\n", + "\n", + "# If you run this notebook on Google Colab, or in standalone mode, you need to install the required packages.\n", + "# Uncomment the following lines:\n", + "\n", + "# !pip install choice-learn\n", + "\n", + "# If you run the notebook within the GitHub repository, you need to run the following lines, that can skipped otherwise:\n", "import os\n", + "import sys\n", "\n", + "sys.path.append(\"../../\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import os\n", "os.environ[\"CUDA_VISIBLE_DEVICES\"] = \"\"\n", - "import sys\n", - "sys.path.append(\"../../\")\n", "\n", "import numpy as np\n", "import pandas as pd\n",