[](https://travis-ci.com/arteagac/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](examples/data/fishing_long.csv) and more information about the data [here](https://doi.org/10.1162/003465399767923827). 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"` normal, `"ln"` lognormal, `"t"` triangular, `"u"` uniform, `"tn"` truncated normal)
The current version of `xlogit` only supports data in long format.
#### Usage
```python
# Read data from CSV file
import pandas as pd
df = pd.read_csv("examples/data/fishing_long.csv")
X = df[['price', 'catch']]
y = df['choice']
# Fit the model with xlogit
from xlogit import MixedLogit
model = MixedLogit()
model.fit(X, y,
varnames=['price', 'catch'],
id=df['id'],
alt=df['alt'],
randvars={'price': 'n', 'catch': 'n'})
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
AIC= 2608.454
BIC= 2628.754
Estimation time= 0.7 seconds
```
For more examples of `xlogit` see [this Jupyter Notebook](https://github.com/arteagac/xlogit/blob/master/examples/mixed_logit_model.ipynb).
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](https://docs.cupy.dev/en/stable/install.html)). When xlogit detects that CuPy is installed, it switches to GPU processing.
## Notes:
The current version allows estimation of:
- Mixed logit models with normal, lognormal, triangular, uniform, and truncated normal distributions.
- Mixed logit models with panel data (balanced or unbalanced).
- Multinomial Logit Models: Models with individual specific variables
- Conditional Logit Models: Models with alternative specific variables
- Models with both, individual and alternative specific variables
Raw data
{
"_id": null,
"home_page": "https://github.com/PrithviBhatB/xlogit",
"name": "xlogitprit",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.5",
"maintainer_email": "",
"keywords": "",
"author": "Ryan Kelly",
"author_email": "ryan@kiiii.com",
"download_url": "https://files.pythonhosted.org/packages/cc/74/3ee52a2e479bc1069a66b0ace5afac64947deafe7cde475482ea9425c9c1/xlogitprit-0.0.7.tar.gz",
"platform": "",
"description": "[](https://travis-ci.com/arteagac/xlogit)\n\n# xlogit\nA Python package for GPU-accelerated estimation of mixed logit models. \nMultinomial and conditional logit models are also supported.\n\n### Example:\nThe following example analyzes choices of fishing modes. See the data [here](examples/data/fishing_long.csv) and more information about the data [here](https://doi.org/10.1162/003465399767923827). The parameters are:\n- `X`: Data matrix in long format (numpy array, shape [n_samples, n_variables])\n- `y`: Binary vector of choices (numpy array, shape [n_samples, ])\n- `varnames`: List of variable names. Its length must match number of columns in `X`\n- `alt`: List of alternatives names or codes.\n- `randvars`: Variables with random distribution. (`\"n\"` normal, `\"ln\"` lognormal, `\"t\"` triangular, `\"u\"` uniform, `\"tn\"` truncated normal)\n\nThe current version of `xlogit` only supports data in long format.\n\n#### Usage\n```python\n# Read data from CSV file\nimport pandas as pd\ndf = pd.read_csv(\"examples/data/fishing_long.csv\")\n\nX = df[['price', 'catch']]\ny = df['choice']\n\n# Fit the model with xlogit\nfrom xlogit import MixedLogit\nmodel = MixedLogit()\nmodel.fit(X, y,\n varnames=['price', 'catch'],\n id=df['id'],\n alt=df['alt'],\n randvars={'price': 'n', 'catch': 'n'})\nmodel.summary()\n```\n\n#### Output\n```\nEstimation succesfully completed after 21 iterations.\n------------------------------------------------------------------------\nCoefficient Estimate Std.Err. z-val P>|z|\n------------------------------------------------------------------------\nprice -0.0274061 0.0022827 -12.0062499 2.2e-30 ***\ncatch 1.3345446 0.1735364 7.6902874 2.29e-13 ***\nsd.price 0.0104608 0.0020466 5.1113049 1.93e-06 ***\nsd.catch 1.5857201 0.3746104 4.2329844 0.000109 ***\n------------------------------------------------------------------------\nSignificance: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1\n\nLog-Likelihood= -1300.227\nAIC= 2608.454\nBIC= 2628.754\nEstimation time= 0.7 seconds\n```\nFor more examples of `xlogit` see [this Jupyter Notebook](https://github.com/arteagac/xlogit/blob/master/examples/mixed_logit_model.ipynb).\nTo 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.\n\n## Installation\nInstall using pip: \n`pip install xlogit` \nAlternatively, you can download source code and import `xlogit.MixedLogit`\n\n### Enable GPU Processsing\nTo enable GPU processing you must install the CuPy library ([see installation instructions](https://docs.cupy.dev/en/stable/install.html)). When xlogit detects that CuPy is installed, it switches to GPU processing.\n\n## Notes:\nThe current version allows estimation of:\n- Mixed logit models with normal, lognormal, triangular, uniform, and truncated normal distributions.\n- Mixed logit models with panel data (balanced or unbalanced).\n- Multinomial Logit Models: Models with individual specific variables\n- Conditional Logit Models: Models with alternative specific variables\n- Models with both, individual and alternative specific variables\n\n\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A Python package for GPU-accelerated estimation of mixed logit models.",
"version": "0.0.7",
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"md5": "2aa97667d633478069f974f616ea080a",
"sha256": "f1abaa872e0322bb98c1c23538ab0657bf180cde06efc3d4fb93ec69e542afd8"
},
"downloads": -1,
"filename": "xlogitprit-0.0.7-py3-none-any.whl",
"has_sig": false,
"md5_digest": "2aa97667d633478069f974f616ea080a",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.5",
"size": 41176,
"upload_time": "2021-01-20T01:49:12",
"upload_time_iso_8601": "2021-01-20T01:49:12.572364Z",
"url": "https://files.pythonhosted.org/packages/b5/9a/cbe623bec46eb9685f0dce2760dc1045e0ba729e3969b332fa6d149b1697/xlogitprit-0.0.7-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"md5": "18426a0ab1de06ae247fabb7cc3dbbef",
"sha256": "fe1a7af50e24fa86315c03e2642303fc980f2afd88cd6e93c363bd6c5511d1dd"
},
"downloads": -1,
"filename": "xlogitprit-0.0.7.tar.gz",
"has_sig": false,
"md5_digest": "18426a0ab1de06ae247fabb7cc3dbbef",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.5",
"size": 22415,
"upload_time": "2021-01-20T01:49:13",
"upload_time_iso_8601": "2021-01-20T01:49:13.748084Z",
"url": "https://files.pythonhosted.org/packages/cc/74/3ee52a2e479bc1069a66b0ace5afac64947deafe7cde475482ea9425c9c1/xlogitprit-0.0.7.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2021-01-20 01:49:13",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": null,
"github_project": "PrithviBhatB",
"error": "Could not fetch GitHub repository",
"lcname": "xlogitprit"
}