Skip to main content

A Python package for GPU-accelerated estimation of mixed logit models.

Project description

Build Status

xlogit

xlogit: A Python package for GPU-accelerated estimation of mixed logit models.
Multinomial and conditional logit models are also supported.

Example:

The following example analyzes choices of fishing modes. See the data here and more information about the data here. The parameters are:

  • X: Data matrix in long format (numpy array, shape [n_samples, n_variables])
  • y: Binary vector of choices (numpy array, shape [n_samples, ])
  • varnames: List of variable names. Its length must match number of columns in X
  • alt: List of alternatives names or codes.
  • randvars: Variables with random distribution. "n" for normal and "ln" for log normal.

The current version of xlogit only supports data in long format.

Usage

# Read data from CSV file
import pandas as pd
df = pd.read_csv("examples/data/fishing_long.csv")

X = df[['price', 'catch']].values
y = df['choice'].values

# Fit the model with xlogit
from xlogit import MixedLogit
model = MixedLogit()
model.fit(X, y, 
          varnames=['price', 'catch'],
          randvars={'price': 'n', 'catch': 'n'},
          alt=['beach', 'boat', 'charter', 'pier'])
model.summary()

Output

Estimation succesfully completed after 21 iterations.
------------------------------------------------------------------------
Coefficient           Estimate      Std.Err.         z-val         P>|z|
------------------------------------------------------------------------
price               -0.0274061     0.0022827   -12.0062499       2.2e-30 ***
catch                1.3345446     0.1735364     7.6902874      2.29e-13 ***
sd.price             0.0104608     0.0020466     5.1113049      1.93e-06 ***
sd.catch             1.5857201     0.3746104     4.2329844      0.000109 ***
------------------------------------------------------------------------
Significance:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Log-Likelihood= -1300.227

For more examples of xlogit see this Jupyter Notebook. To test how fast is MixedLogit with GPU processing you can use Google Colaboratory that provides some GPU processing for free. In the Jupyter Notebook above you just need to click the "Open in Colab" button to run your analysis.

Installation

Install using pip:
pip install xlogit
Alternatively, you can download source code and import xlogit.MixedLogit

Enable GPU Processsing

To enable GPU processing you must install the CuPy library (see installation instructions). When xlogit detects that CuPy is installed, it switches to GPU processing.

Notes:

The current version allows estimation of:

  • Mixed logit models with normal and log-normal distributions.
  • Mixed logit models with panel data
  • Multinomial Logit Models: Models with individual specific variables
  • Conditional Logit Models: Models with alternative specific variables
  • Models with both, individual and alternative specific variables

Citing xlogit

To cite this package:

BibTeX

@software{xlogit,
    author = {Arteaga, Cristian and Bhat, Prithvi and Park, JeeWoong and Paz, Alexander},
    title = {xlogit: xlogit: A Python package for GPU-accelerated estimation of mixed logit models},
    url = {https://github.com/arteagac/xlogit},
    version = {0.0.2},
    year = {2020}
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

xlogit-0.0.1.tar.gz (8.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

xlogit-0.0.1-py3-none-any.whl (11.4 kB view details)

Uploaded Python 3

File details

Details for the file xlogit-0.0.1.tar.gz.

File metadata

  • Download URL: xlogit-0.0.1.tar.gz
  • Upload date:
  • Size: 8.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0.post20200714 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.6.10

File hashes

Hashes for xlogit-0.0.1.tar.gz
Algorithm Hash digest
SHA256 e1f6d9a5b8491894e86085e000e67fab8b4fd1a2caab914dad8ac705920d4727
MD5 bec026a4d041b1463d84e20fbe81d44a
BLAKE2b-256 dd2fc452b28fd8149957ae805d69eb08fb7a1ee6713b6cc3029d67cc5b94e2e1

See more details on using hashes here.

File details

Details for the file xlogit-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: xlogit-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 11.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0.post20200714 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.6.10

File hashes

Hashes for xlogit-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c0d320670e4987cae1540adb2c7c682c236119a4d9147535b44861efda15977c
MD5 47ac4c259d26655be19aa2addac09ec7
BLAKE2b-256 22c325e3dad31a12f4f169e6b2f601ad69c7f9a86ad981f2a7c7330d213f2f3f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page