dcmbench 0.1.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- dcmbench-0.1.2/LICENSE +21 -0
- dcmbench-0.1.2/MANIFEST.in +63 -0
- dcmbench-0.1.2/PKG-INFO +196 -0
- dcmbench-0.1.2/README.md +146 -0
- dcmbench-0.1.2/dcmbench/__init__.py +25 -0
- dcmbench-0.1.2/dcmbench/adapters/__init__.py +107 -0
- dcmbench-0.1.2/dcmbench/adapters/biogeme_adapter.py +487 -0
- dcmbench-0.1.2/dcmbench/adapters/biogeme_vot_adapter.py +385 -0
- dcmbench-0.1.2/dcmbench/adapters/enhanced_biogeme_adapter.py +218 -0
- dcmbench-0.1.2/dcmbench/adapters/factory.py +678 -0
- dcmbench-0.1.2/dcmbench/adapters/pytorch_adapter.py +514 -0
- dcmbench-0.1.2/dcmbench/adapters/pytorch_model.py +770 -0
- dcmbench-0.1.2/dcmbench/adapters/sklearn_adapter.py +554 -0
- dcmbench-0.1.2/dcmbench/adapters/sklearn_model.py +606 -0
- dcmbench-0.1.2/dcmbench/adapters/universal_biogeme_adapter.py +1324 -0
- dcmbench-0.1.2/dcmbench/adapters/universal_biogeme_adapter_backup.py +894 -0
- dcmbench-0.1.2/dcmbench/datasets/__init__.py +64 -0
- dcmbench-0.1.2/dcmbench/datasets/dataset_loader.py +387 -0
- dcmbench-0.1.2/dcmbench/datasets/metadata.json +29 -0
- dcmbench-0.1.2/dcmbench/datasets/simple_fetcher.py +84 -0
- dcmbench-0.1.2/dcmbench/model_benchmarker/__init__.py +7 -0
- dcmbench-0.1.2/dcmbench/model_benchmarker/benchmarker.py +403 -0
- dcmbench-0.1.2/dcmbench/model_benchmarker/model_interface.py +124 -0
- dcmbench-0.1.2/dcmbench/model_specifications.py +559 -0
- dcmbench-0.1.2/dcmbench/utils/__init__.py +91 -0
- dcmbench-0.1.2/dcmbench/utils/biogeme_wrapper.py +245 -0
- dcmbench-0.1.2/dcmbench/utils/individual_parameters.py +488 -0
- dcmbench-0.1.2/dcmbench/utils/metrics.py +482 -0
- dcmbench-0.1.2/dcmbench/utils/model_extensions.py +359 -0
- dcmbench-0.1.2/dcmbench/utils/policy_analysis.py +845 -0
- dcmbench-0.1.2/dcmbench/utils/preprocessing.py +318 -0
- dcmbench-0.1.2/dcmbench/utils/sensitivity_analysis.py +873 -0
- dcmbench-0.1.2/dcmbench/utils/vot_analysis.py +799 -0
- dcmbench-0.1.2/dcmbench/utils/vot_systematic.py +271 -0
- dcmbench-0.1.2/dcmbench/utils/vot_visualization.py +565 -0
- dcmbench-0.1.2/dcmbench.egg-info/PKG-INFO +196 -0
- dcmbench-0.1.2/dcmbench.egg-info/SOURCES.txt +41 -0
- dcmbench-0.1.2/dcmbench.egg-info/dependency_links.txt +1 -0
- dcmbench-0.1.2/dcmbench.egg-info/requires.txt +20 -0
- dcmbench-0.1.2/dcmbench.egg-info/top_level.txt +1 -0
- dcmbench-0.1.2/pyproject.toml +68 -0
- dcmbench-0.1.2/setup.cfg +4 -0
- dcmbench-0.1.2/setup.py +66 -0
dcmbench-0.1.2/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Carlos Guirado
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# Include documentation and license
|
|
2
|
+
include README.md
|
|
3
|
+
include LICENSE
|
|
4
|
+
|
|
5
|
+
# Include essential package data
|
|
6
|
+
include dcmbench/datasets/metadata.json
|
|
7
|
+
|
|
8
|
+
# Exclude all test and example directories
|
|
9
|
+
prune tests
|
|
10
|
+
prune examples
|
|
11
|
+
prune Aug25_test
|
|
12
|
+
prune docs
|
|
13
|
+
prune notebook_env
|
|
14
|
+
prune pytorch_env
|
|
15
|
+
prune test_env
|
|
16
|
+
|
|
17
|
+
# Exclude version control and cache files
|
|
18
|
+
global-exclude .git*
|
|
19
|
+
global-exclude *.pyc
|
|
20
|
+
global-exclude *.pyo
|
|
21
|
+
global-exclude __pycache__
|
|
22
|
+
global-exclude .DS_Store
|
|
23
|
+
global-exclude *.swp
|
|
24
|
+
global-exclude *~
|
|
25
|
+
global-exclude .pytest_cache
|
|
26
|
+
|
|
27
|
+
# Exclude Jupyter notebook checkpoints
|
|
28
|
+
global-exclude .ipynb_checkpoints
|
|
29
|
+
|
|
30
|
+
# Exclude build artifacts
|
|
31
|
+
global-exclude *.egg-info
|
|
32
|
+
prune build
|
|
33
|
+
prune dist
|
|
34
|
+
|
|
35
|
+
# Exclude Biogeme output files
|
|
36
|
+
global-exclude *.html
|
|
37
|
+
global-exclude *.pickle
|
|
38
|
+
global-exclude *.iter
|
|
39
|
+
|
|
40
|
+
# Exclude image files from root
|
|
41
|
+
global-exclude *.png
|
|
42
|
+
global-exclude *.jpg
|
|
43
|
+
global-exclude *.jpeg
|
|
44
|
+
global-exclude *.gif
|
|
45
|
+
|
|
46
|
+
# Exclude backup files
|
|
47
|
+
global-exclude *.backup
|
|
48
|
+
|
|
49
|
+
# Exclude CSV and compressed data files (users should fetch via API)
|
|
50
|
+
global-exclude *.csv
|
|
51
|
+
global-exclude *.csv.gz
|
|
52
|
+
global-exclude *.zip
|
|
53
|
+
|
|
54
|
+
# Exclude environment and virtual env directories
|
|
55
|
+
prune venv
|
|
56
|
+
prune env
|
|
57
|
+
prune .env
|
|
58
|
+
prune *_env
|
|
59
|
+
|
|
60
|
+
# Exclude IDE files
|
|
61
|
+
global-exclude .vscode
|
|
62
|
+
global-exclude .idea
|
|
63
|
+
global-exclude *.iml
|
dcmbench-0.1.2/PKG-INFO
ADDED
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: dcmbench
|
|
3
|
+
Version: 0.1.2
|
|
4
|
+
Summary: A comprehensive benchmarking framework for discrete choice models
|
|
5
|
+
Home-page: https://github.com/carlosguirado/dcmbench
|
|
6
|
+
Author: Carlos Guirado
|
|
7
|
+
Author-email: Carlos Guirado <your.email@example.com>
|
|
8
|
+
Maintainer-email: Carlos Guirado <your.email@example.com>
|
|
9
|
+
License: MIT
|
|
10
|
+
Project-URL: Homepage, https://github.com/carlosguirado/dcmbench
|
|
11
|
+
Project-URL: Documentation, https://dcmbench.readthedocs.io
|
|
12
|
+
Project-URL: Repository, https://github.com/carlosguirado/dcmbench.git
|
|
13
|
+
Project-URL: Bug Tracker, https://github.com/carlosguirado/dcmbench/issues
|
|
14
|
+
Keywords: discrete choice,benchmarking,transportation,econometrics,machine learning
|
|
15
|
+
Classifier: Development Status :: 4 - Beta
|
|
16
|
+
Classifier: Intended Audience :: Science/Research
|
|
17
|
+
Classifier: Topic :: Scientific/Engineering
|
|
18
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
19
|
+
Classifier: Programming Language :: Python :: 3
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
24
|
+
Classifier: Operating System :: OS Independent
|
|
25
|
+
Requires-Python: >=3.8
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
License-File: LICENSE
|
|
28
|
+
Requires-Dist: numpy>=1.19.0
|
|
29
|
+
Requires-Dist: pandas>=1.2.0
|
|
30
|
+
Requires-Dist: scikit-learn>=0.24.0
|
|
31
|
+
Requires-Dist: matplotlib>=3.3.0
|
|
32
|
+
Requires-Dist: seaborn>=0.11.0
|
|
33
|
+
Requires-Dist: biogeme>=3.2.0
|
|
34
|
+
Requires-Dist: requests>=2.25.0
|
|
35
|
+
Requires-Dist: scipy>=1.6.0
|
|
36
|
+
Provides-Extra: dev
|
|
37
|
+
Requires-Dist: pytest>=6.0; extra == "dev"
|
|
38
|
+
Requires-Dist: pytest-cov>=2.0; extra == "dev"
|
|
39
|
+
Requires-Dist: black>=22.0; extra == "dev"
|
|
40
|
+
Requires-Dist: flake8>=4.0; extra == "dev"
|
|
41
|
+
Requires-Dist: mypy>=0.900; extra == "dev"
|
|
42
|
+
Requires-Dist: sphinx>=4.0; extra == "dev"
|
|
43
|
+
Requires-Dist: sphinx-rtd-theme>=1.0; extra == "dev"
|
|
44
|
+
Provides-Extra: pytorch
|
|
45
|
+
Requires-Dist: torch>=1.10.0; extra == "pytorch"
|
|
46
|
+
Dynamic: author
|
|
47
|
+
Dynamic: home-page
|
|
48
|
+
Dynamic: license-file
|
|
49
|
+
Dynamic: requires-python
|
|
50
|
+
|
|
51
|
+
# Discrete Choice Model Benchmarking (DCMBench)
|
|
52
|
+
|
|
53
|
+
A comprehensive Python package for benchmarking, analyzing, and validating discrete choice models for transportation mode choice analysis. DCMBench provides a unified framework for comparing different model specifications, conducting sensitivity analysis, and visualizing results.
|
|
54
|
+
|
|
55
|
+
## Installation
|
|
56
|
+
|
|
57
|
+
You can install DCMBench using pip:
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
pip install dcmbench
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Key Features
|
|
64
|
+
|
|
65
|
+
### Model Estimation and Benchmarking
|
|
66
|
+
|
|
67
|
+
- **Multiple Model Types**: Support for Multinomial Logit (MNL), Nested Logit (NL), and Mixed Logit (ML) models
|
|
68
|
+
- **Standardized Metrics**: Compare models using log-likelihood, rho-squared, prediction accuracy, and market share
|
|
69
|
+
- **Cross-validation**: Evaluate model performance on training and testing datasets
|
|
70
|
+
- **Visualization**: Generate comparative plots showing model performance across different metrics
|
|
71
|
+
|
|
72
|
+
```python
|
|
73
|
+
from dcmbench.model_benchmarker import Benchmarker
|
|
74
|
+
from dcmbench.datasets import fetch_data
|
|
75
|
+
|
|
76
|
+
# Load dataset (automatically downloads if not in local cache)
|
|
77
|
+
data = fetch_data("swissmetro_dataset")
|
|
78
|
+
|
|
79
|
+
# Define models and run benchmark
|
|
80
|
+
benchmarker = Benchmarker()
|
|
81
|
+
benchmarker.register_model(models, "Model Name")
|
|
82
|
+
results = benchmarker.run_benchmark(data, choice_column="CHOICE")
|
|
83
|
+
benchmarker.print_comparison()
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### Advanced Analysis Capabilities
|
|
87
|
+
|
|
88
|
+
- **Sensitivity Analysis**: Evaluate how model predictions change with variations in key variables
|
|
89
|
+
- Simulate changes in travel times, costs, and other attributes
|
|
90
|
+
- Generate plots showing the evolution of market shares under different scenarios
|
|
91
|
+
|
|
92
|
+
- **Individual-Level Parameters**: For Mixed Logit models, calculate and visualize:
|
|
93
|
+
- Individual-specific parameter distributions using Bayesian approaches
|
|
94
|
+
- Value of Time (VOT) distributions across the population
|
|
95
|
+
- Heterogeneity in preference structures
|
|
96
|
+
|
|
97
|
+
- **Model Calibration**: Automatically calibrate Alternative Specific Constants (ASCs) to match observed market shares
|
|
98
|
+
|
|
99
|
+
### Visualization and Reporting
|
|
100
|
+
|
|
101
|
+
- **Market Share Analysis**: Compare predicted vs. observed mode shares
|
|
102
|
+
- **Performance Plots**: Visualize how different models perform across multiple datasets
|
|
103
|
+
- **Parameter Distributions**: Plot distributions of random parameters and derived metrics like VOT
|
|
104
|
+
- **Sensitivity Curves**: Show how predicted mode shares change with variations in key variables
|
|
105
|
+
|
|
106
|
+
## Supported Datasets
|
|
107
|
+
|
|
108
|
+
- **Swissmetro** (`swissmetro_dataset`): Swiss inter-city travel mode choice
|
|
109
|
+
- **London Transport** (`ltds_dataset`): London Travel Demand Survey with urban mode choices
|
|
110
|
+
- **ModeCanada** (`modecanada_dataset`): Canadian inter-city travel dataset
|
|
111
|
+
|
|
112
|
+
Datasets are automatically downloaded from the [dcmbench-datasets](https://github.com/carlosguirado/dcmbench-datasets) repository on first use and cached locally:
|
|
113
|
+
|
|
114
|
+
```python
|
|
115
|
+
from dcmbench.datasets import fetch_data
|
|
116
|
+
|
|
117
|
+
# Use default cache location (~/.dcmbench/datasets)
|
|
118
|
+
data = fetch_data("swissmetro_dataset")
|
|
119
|
+
|
|
120
|
+
# Specify custom cache location
|
|
121
|
+
data = fetch_data("swissmetro_dataset", local_cache_dir="/path/to/cache")
|
|
122
|
+
|
|
123
|
+
# Get features and target separately
|
|
124
|
+
X, y = fetch_data("swissmetro_dataset", return_X_y=True)
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## Example Applications
|
|
128
|
+
|
|
129
|
+
### Benchmarking Multiple Models
|
|
130
|
+
|
|
131
|
+
The package includes tools to benchmark multiple model types across different datasets:
|
|
132
|
+
|
|
133
|
+
```python
|
|
134
|
+
# Run benchmark_all_models.py to compare models across datasets
|
|
135
|
+
python benchmark_all_models.py
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
This generates comparative visualizations showing how different model types perform across datasets, plotting metrics like choice accuracy and market share accuracy against model fit.
|
|
139
|
+
|
|
140
|
+
### Sensitivity Analysis
|
|
141
|
+
|
|
142
|
+
Analyze how changes in key variables affect predicted mode shares:
|
|
143
|
+
|
|
144
|
+
```python
|
|
145
|
+
# Run sensitivity analysis on ModeCanada models
|
|
146
|
+
python sensitivity_analysis.py
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
This creates plots showing the evolution of mode shares as you modify variables like:
|
|
150
|
+
- Travel costs for different modes
|
|
151
|
+
- Travel times
|
|
152
|
+
- Service frequencies
|
|
153
|
+
|
|
154
|
+
### Individual Parameter Analysis
|
|
155
|
+
|
|
156
|
+
For Mixed Logit models, analyze individual-level parameters and VOT:
|
|
157
|
+
|
|
158
|
+
```python
|
|
159
|
+
# Generate individual parameter distributions for ModeCanada
|
|
160
|
+
python plot_individual_parameters_canada.py
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
This calculates individual-specific parameters using Bayesian conditioning and produces:
|
|
164
|
+
- Distributions of time and cost parameters
|
|
165
|
+
- Value of Time (VOT) distributions
|
|
166
|
+
- Summary statistics for preference heterogeneity
|
|
167
|
+
|
|
168
|
+
## Requirements
|
|
169
|
+
|
|
170
|
+
- Python >=3.8
|
|
171
|
+
- NumPy >=2.0.0
|
|
172
|
+
- Pandas >=2.0.0
|
|
173
|
+
- Biogeme >=3.2.14
|
|
174
|
+
- Matplotlib >=3.0.0
|
|
175
|
+
- Requests >=2.25.0
|
|
176
|
+
- SciPy (for statistical functions)
|
|
177
|
+
- Seaborn (for advanced visualizations)
|
|
178
|
+
|
|
179
|
+
## License
|
|
180
|
+
|
|
181
|
+
This project is licensed under the MIT License - see the LICENSE file for details.
|
|
182
|
+
|
|
183
|
+
## Contributing
|
|
184
|
+
|
|
185
|
+
We welcome contributions! Please see our contributing guidelines for details.
|
|
186
|
+
|
|
187
|
+
### Adding New Datasets
|
|
188
|
+
|
|
189
|
+
To add a new dataset to the DCMBench ecosystem:
|
|
190
|
+
|
|
191
|
+
1. Fork the [dcmbench-datasets](https://github.com/carlosguirado/dcmbench-datasets) repository
|
|
192
|
+
2. Add your dataset following the structure guidelines in the repository's CONTRIBUTING.md file
|
|
193
|
+
3. Submit a pull request to the dcmbench-datasets repository
|
|
194
|
+
4. Update the metadata.json file in the main DCMBench package to include your dataset information
|
|
195
|
+
|
|
196
|
+
This design allows the package to remain lightweight while providing access to a growing collection of transportation mode choice datasets.
|
dcmbench-0.1.2/README.md
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
# Discrete Choice Model Benchmarking (DCMBench)
|
|
2
|
+
|
|
3
|
+
A comprehensive Python package for benchmarking, analyzing, and validating discrete choice models for transportation mode choice analysis. DCMBench provides a unified framework for comparing different model specifications, conducting sensitivity analysis, and visualizing results.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
You can install DCMBench using pip:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pip install dcmbench
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Key Features
|
|
14
|
+
|
|
15
|
+
### Model Estimation and Benchmarking
|
|
16
|
+
|
|
17
|
+
- **Multiple Model Types**: Support for Multinomial Logit (MNL), Nested Logit (NL), and Mixed Logit (ML) models
|
|
18
|
+
- **Standardized Metrics**: Compare models using log-likelihood, rho-squared, prediction accuracy, and market share
|
|
19
|
+
- **Cross-validation**: Evaluate model performance on training and testing datasets
|
|
20
|
+
- **Visualization**: Generate comparative plots showing model performance across different metrics
|
|
21
|
+
|
|
22
|
+
```python
|
|
23
|
+
from dcmbench.model_benchmarker import Benchmarker
|
|
24
|
+
from dcmbench.datasets import fetch_data
|
|
25
|
+
|
|
26
|
+
# Load dataset (automatically downloads if not in local cache)
|
|
27
|
+
data = fetch_data("swissmetro_dataset")
|
|
28
|
+
|
|
29
|
+
# Define models and run benchmark
|
|
30
|
+
benchmarker = Benchmarker()
|
|
31
|
+
benchmarker.register_model(models, "Model Name")
|
|
32
|
+
results = benchmarker.run_benchmark(data, choice_column="CHOICE")
|
|
33
|
+
benchmarker.print_comparison()
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### Advanced Analysis Capabilities
|
|
37
|
+
|
|
38
|
+
- **Sensitivity Analysis**: Evaluate how model predictions change with variations in key variables
|
|
39
|
+
- Simulate changes in travel times, costs, and other attributes
|
|
40
|
+
- Generate plots showing the evolution of market shares under different scenarios
|
|
41
|
+
|
|
42
|
+
- **Individual-Level Parameters**: For Mixed Logit models, calculate and visualize:
|
|
43
|
+
- Individual-specific parameter distributions using Bayesian approaches
|
|
44
|
+
- Value of Time (VOT) distributions across the population
|
|
45
|
+
- Heterogeneity in preference structures
|
|
46
|
+
|
|
47
|
+
- **Model Calibration**: Automatically calibrate Alternative Specific Constants (ASCs) to match observed market shares
|
|
48
|
+
|
|
49
|
+
### Visualization and Reporting
|
|
50
|
+
|
|
51
|
+
- **Market Share Analysis**: Compare predicted vs. observed mode shares
|
|
52
|
+
- **Performance Plots**: Visualize how different models perform across multiple datasets
|
|
53
|
+
- **Parameter Distributions**: Plot distributions of random parameters and derived metrics like VOT
|
|
54
|
+
- **Sensitivity Curves**: Show how predicted mode shares change with variations in key variables
|
|
55
|
+
|
|
56
|
+
## Supported Datasets
|
|
57
|
+
|
|
58
|
+
- **Swissmetro** (`swissmetro_dataset`): Swiss inter-city travel mode choice
|
|
59
|
+
- **London Transport** (`ltds_dataset`): London Travel Demand Survey with urban mode choices
|
|
60
|
+
- **ModeCanada** (`modecanada_dataset`): Canadian inter-city travel dataset
|
|
61
|
+
|
|
62
|
+
Datasets are automatically downloaded from the [dcmbench-datasets](https://github.com/carlosguirado/dcmbench-datasets) repository on first use and cached locally:
|
|
63
|
+
|
|
64
|
+
```python
|
|
65
|
+
from dcmbench.datasets import fetch_data
|
|
66
|
+
|
|
67
|
+
# Use default cache location (~/.dcmbench/datasets)
|
|
68
|
+
data = fetch_data("swissmetro_dataset")
|
|
69
|
+
|
|
70
|
+
# Specify custom cache location
|
|
71
|
+
data = fetch_data("swissmetro_dataset", local_cache_dir="/path/to/cache")
|
|
72
|
+
|
|
73
|
+
# Get features and target separately
|
|
74
|
+
X, y = fetch_data("swissmetro_dataset", return_X_y=True)
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Example Applications
|
|
78
|
+
|
|
79
|
+
### Benchmarking Multiple Models
|
|
80
|
+
|
|
81
|
+
The package includes tools to benchmark multiple model types across different datasets:
|
|
82
|
+
|
|
83
|
+
```python
|
|
84
|
+
# Run benchmark_all_models.py to compare models across datasets
|
|
85
|
+
python benchmark_all_models.py
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
This generates comparative visualizations showing how different model types perform across datasets, plotting metrics like choice accuracy and market share accuracy against model fit.
|
|
89
|
+
|
|
90
|
+
### Sensitivity Analysis
|
|
91
|
+
|
|
92
|
+
Analyze how changes in key variables affect predicted mode shares:
|
|
93
|
+
|
|
94
|
+
```python
|
|
95
|
+
# Run sensitivity analysis on ModeCanada models
|
|
96
|
+
python sensitivity_analysis.py
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
This creates plots showing the evolution of mode shares as you modify variables like:
|
|
100
|
+
- Travel costs for different modes
|
|
101
|
+
- Travel times
|
|
102
|
+
- Service frequencies
|
|
103
|
+
|
|
104
|
+
### Individual Parameter Analysis
|
|
105
|
+
|
|
106
|
+
For Mixed Logit models, analyze individual-level parameters and VOT:
|
|
107
|
+
|
|
108
|
+
```python
|
|
109
|
+
# Generate individual parameter distributions for ModeCanada
|
|
110
|
+
python plot_individual_parameters_canada.py
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
This calculates individual-specific parameters using Bayesian conditioning and produces:
|
|
114
|
+
- Distributions of time and cost parameters
|
|
115
|
+
- Value of Time (VOT) distributions
|
|
116
|
+
- Summary statistics for preference heterogeneity
|
|
117
|
+
|
|
118
|
+
## Requirements
|
|
119
|
+
|
|
120
|
+
- Python >=3.8
|
|
121
|
+
- NumPy >=2.0.0
|
|
122
|
+
- Pandas >=2.0.0
|
|
123
|
+
- Biogeme >=3.2.14
|
|
124
|
+
- Matplotlib >=3.0.0
|
|
125
|
+
- Requests >=2.25.0
|
|
126
|
+
- SciPy (for statistical functions)
|
|
127
|
+
- Seaborn (for advanced visualizations)
|
|
128
|
+
|
|
129
|
+
## License
|
|
130
|
+
|
|
131
|
+
This project is licensed under the MIT License - see the LICENSE file for details.
|
|
132
|
+
|
|
133
|
+
## Contributing
|
|
134
|
+
|
|
135
|
+
We welcome contributions! Please see our contributing guidelines for details.
|
|
136
|
+
|
|
137
|
+
### Adding New Datasets
|
|
138
|
+
|
|
139
|
+
To add a new dataset to the DCMBench ecosystem:
|
|
140
|
+
|
|
141
|
+
1. Fork the [dcmbench-datasets](https://github.com/carlosguirado/dcmbench-datasets) repository
|
|
142
|
+
2. Add your dataset following the structure guidelines in the repository's CONTRIBUTING.md file
|
|
143
|
+
3. Submit a pull request to the dcmbench-datasets repository
|
|
144
|
+
4. Update the metadata.json file in the main DCMBench package to include your dataset information
|
|
145
|
+
|
|
146
|
+
This design allows the package to remain lightweight while providing access to a growing collection of transportation mode choice datasets.
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# dcmbench/__init__.py
|
|
2
|
+
|
|
3
|
+
from .datasets import DatasetLoader
|
|
4
|
+
from . import datasets
|
|
5
|
+
from . import model_benchmarker
|
|
6
|
+
from .model_specifications import (
|
|
7
|
+
fetch_model_spec,
|
|
8
|
+
build_model_from_spec,
|
|
9
|
+
model_to_spec,
|
|
10
|
+
list_available_specs,
|
|
11
|
+
validate_model_spec
|
|
12
|
+
)
|
|
13
|
+
# Do not import models to avoid circular imports
|
|
14
|
+
# from . import models
|
|
15
|
+
|
|
16
|
+
__all__ = [
|
|
17
|
+
'DatasetLoader',
|
|
18
|
+
'datasets',
|
|
19
|
+
'model_benchmarker',
|
|
20
|
+
'fetch_model_spec',
|
|
21
|
+
'build_model_from_spec',
|
|
22
|
+
'model_to_spec',
|
|
23
|
+
'list_available_specs',
|
|
24
|
+
'validate_model_spec'
|
|
25
|
+
]
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"""
|
|
2
|
+
DCMBench Adapters Module
|
|
3
|
+
|
|
4
|
+
This module provides adapter classes that make models from different frameworks
|
|
5
|
+
compatible with DCMBench benchmarking by implementing the required prediction interface.
|
|
6
|
+
Adapters allow users to create models using their preferred framework and then
|
|
7
|
+
use them with DCMBench without writing boilerplate prediction code.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
import logging
|
|
11
|
+
|
|
12
|
+
# Set up logging
|
|
13
|
+
logger = logging.getLogger(__name__)
|
|
14
|
+
|
|
15
|
+
# Import base interfaces
|
|
16
|
+
from ..model_benchmarker.model_interface import PredictionInterface
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
# Register Biogeme adapters - always available
|
|
20
|
+
from .biogeme_adapter import (
|
|
21
|
+
BiogemeModelAdapter,
|
|
22
|
+
BiogemeMultinomialLogitAdapter,
|
|
23
|
+
BiogemeNestedLogitAdapter,
|
|
24
|
+
BiogemeModelFromSpecAdapter
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
# Import enhanced adapters
|
|
29
|
+
try:
|
|
30
|
+
from .enhanced_biogeme_adapter import EnhancedBiogemeAdapter
|
|
31
|
+
from .biogeme_vot_adapter import BiogemeVOTAdapter
|
|
32
|
+
_has_enhanced_adapters = True
|
|
33
|
+
except ImportError:
|
|
34
|
+
logger.info("Enhanced adapters not available")
|
|
35
|
+
_has_enhanced_adapters = False
|
|
36
|
+
|
|
37
|
+
# Biogeme adapters - always available
|
|
38
|
+
logger.info("Biogeme adapters available")
|
|
39
|
+
|
|
40
|
+
# PyTorch adapters if available
|
|
41
|
+
try:
|
|
42
|
+
from .pytorch_adapter import (
|
|
43
|
+
PyTorchModelAdapter,
|
|
44
|
+
PyTorchMultinomialLogitAdapter
|
|
45
|
+
)
|
|
46
|
+
_has_pytorch = True
|
|
47
|
+
logger.info("PyTorch adapters available")
|
|
48
|
+
except ImportError:
|
|
49
|
+
logger.info("PyTorch not available, skipping PyTorch adapters")
|
|
50
|
+
_has_pytorch = False
|
|
51
|
+
|
|
52
|
+
# scikit-learn adapters if available
|
|
53
|
+
try:
|
|
54
|
+
from .sklearn_adapter import (
|
|
55
|
+
SklearnModelAdapter,
|
|
56
|
+
LogisticRegressionAdapter
|
|
57
|
+
)
|
|
58
|
+
_has_sklearn = True
|
|
59
|
+
logger.info("scikit-learn adapters available")
|
|
60
|
+
except ImportError:
|
|
61
|
+
logger.info("scikit-learn not available, skipping scikit-learn adapters")
|
|
62
|
+
_has_sklearn = False
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
# Define __all__ with essential components
|
|
66
|
+
__all__ = [
|
|
67
|
+
# Base interfaces
|
|
68
|
+
'PredictionInterface',
|
|
69
|
+
|
|
70
|
+
# Factory function
|
|
71
|
+
'create_model_adapter',
|
|
72
|
+
|
|
73
|
+
# Biogeme adapters - always available
|
|
74
|
+
'BiogemeModelAdapter',
|
|
75
|
+
'BiogemeMultinomialLogitAdapter',
|
|
76
|
+
'BiogemeNestedLogitAdapter',
|
|
77
|
+
'BiogemeModelFromSpecAdapter',
|
|
78
|
+
|
|
79
|
+
]
|
|
80
|
+
|
|
81
|
+
# Add enhanced adapters to __all__ if available
|
|
82
|
+
if _has_enhanced_adapters:
|
|
83
|
+
__all__.extend([
|
|
84
|
+
'EnhancedBiogemeAdapter',
|
|
85
|
+
'BiogemeVOTAdapter'
|
|
86
|
+
])
|
|
87
|
+
|
|
88
|
+
# Add PyTorch adapters to __all__ if available
|
|
89
|
+
if _has_pytorch:
|
|
90
|
+
__all__.extend([
|
|
91
|
+
'PyTorchModelAdapter',
|
|
92
|
+
'PyTorchMultinomialLogitAdapter'
|
|
93
|
+
])
|
|
94
|
+
|
|
95
|
+
# Add scikit-learn adapters to __all__ if available
|
|
96
|
+
if _has_sklearn:
|
|
97
|
+
__all__.extend([
|
|
98
|
+
'SklearnModelAdapter',
|
|
99
|
+
'LogisticRegressionAdapter'
|
|
100
|
+
])
|
|
101
|
+
|
|
102
|
+
# Log available frameworks
|
|
103
|
+
if _has_pytorch:
|
|
104
|
+
logger.debug("PyTorch adapters available")
|
|
105
|
+
if _has_sklearn:
|
|
106
|
+
logger.debug("scikit-learn adapters available")
|
|
107
|
+
logger.debug("Biogeme adapters available")
|