Skip to content

Commit

Permalink
Merge pull request #8 from UDST/tests-ci
Browse files Browse the repository at this point in the history
Consolidate tests, clean up requirements, add CI and coveralls
  • Loading branch information
gboeing committed Jul 24, 2017
2 parents 2c4eb52 + 9291be3 commit e8a3211
Show file tree
Hide file tree
Showing 15 changed files with 82 additions and 24 deletions.
32 changes: 32 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
language: python

python:
- "2.7"

before_install:
- pip install --upgrade pip
- pip install --upgrade wheel
- wget http://bit.ly/miniconda -O miniconda.sh
- bash miniconda.sh -b -p $HOME/miniconda
- export PATH="$HOME/miniconda/bin:$PATH"
- hash -r
- conda config --set always_yes yes --set show_channel_urls true
- conda update conda
- conda config --add channels udst --force
- conda config --add channels conda-forge --force
- conda create --quiet --name TESTENV python=$TRAVIS_PYTHON_VERSION future numpy pandas patsy scipy statsmodels urbansim coverage coveralls pytest
- source activate TESTENV
- pip install pylogit
- conda info --all
- conda list

install:
- pip install .
- pip show choicemodels

script:
- coverage run --source choicemodels -m pytest --verbose

after_success:
- coverage report -m
- coveralls
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
[![Build Status](https://travis-ci.org/UDST/choicemodels.svg?branch=master)](https://travis-ci.org/UDST/choicemodels)
[![Coverage Status](https://coveralls.io/repos/github/UDST/choicemodels/badge.svg?branch=master)](https://coveralls.io/github/UDST/choicemodels?branch=master)

# ChoiceModels

This is a package for discrete choice model estimation and simulation, with an emphasis on large choice sets and behavioral refinements to multinomial models. Most of these models are not available in Statsmodels or Scikit-learn.
This is a package for discrete choice model estimation and simulation, with an emphasis on large choice sets and behavioral refinements to multinomial models. Most of these models are not available in Statsmodels or Scikit-learn.

The underlying estimation routines come from two main places: (1) UrbanSim's `urbanchoice` codebase, which is being moved into ChoiceModels, and (2) Timothy Brathwaite's PyLogit package, which handles more flexible model specifications.


## Installation

Clone this repository and run `python setup.py develop`.
Clone this repository and run `python setup.py develop`.

Two required packages should also be installed the same way:
- PyLogit: https://github.com/timothyb0912/pylogit
Expand All @@ -30,7 +33,7 @@ UrbanSim won't be a requirement any more after we finish refactoring the estimat

- Stores and reports fitted MNL models.

There's documentation in these classes' docstrings, and a usage demo in a Jupyter notebook.
There's documentation in these classes' docstrings, and a usage demo in a Jupyter notebook.

https://github.com/udst/choicemodels/blob/master/choicemodels/tools/interaction.py
https://github.com/udst/choicemodels/blob/master/choicemodels/mnl.py
Expand Down
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@

numalts = 10

merged = MergedChoiceTable(observations = choosers,
alternatives = tracts,
chosen_alternatives = choosers.full_tract_id,
merged = MergedChoiceTable(observations = choosers,
alternatives = tracts,
chosen_alternatives = choosers.full_tract_id,
sample_size = numalts)

model_expression = "home_density + work_density + school_density"

model = MultinomialLogit(merged.to_frame(),
merged.observation_id_col,
model = MultinomialLogit(merged.to_frame(),
merged.observation_id_col,
merged.choice_col,
model_expression)

Expand All @@ -42,7 +42,7 @@
alternative_id_col = merged.alternative_id_col,
choice_col = merged.choice_col,
model_expression = model_expression)
results = model.fit()
print(results.print_summaries())
"""
"""
3 changes: 3 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
coverage
coveralls
pytest
8 changes: 8 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
future >= 0.16.0
numpy >= 1.8.0
pandas >= 0.17.0
patsy >= 0.3.0
pylogit >= 0.1.2
scipy >= 0.13.3
statsmodels >= 0.8.0
urbansim >= 3.1.1
23 changes: 11 additions & 12 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,33 @@
from ez_setup import use_setuptools
use_setuptools()

from setuptools import setup, find_packages
from setuptools import setup


# read README as the long description
with open('README.md', 'r') as f:
long_description = f.read()

with open('requirements.txt') as f:
install_requires = f.readlines()
install_requires = [item.strip() for item in install_requires]

setup(
name='choicemodels',
version='0.1dev',
description='Tools for discrete choice estimation',
long_description=long_description,
author='Urban Analytics Lab',
url='https://github.com/ual/choicemodels',
author='UC Berkeley Urban Analytics Lab',
url='https://github.com/udst/choicemodels',
classifiers=[
'Intended Audience :: Science/Research',
'Topic :: Scientific/Engineering :: Information Analysis',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.6',
'License :: OSI Approved :: BSD License'
],
packages=find_packages(exclude=['*.tests']),
install_requires=[
'future>=0.16.0',
'numpy>=1.8.0',
'pandas>=0.17.0',
'patsy>=0.3.0',
'scipy>=0.13.3',
'statsmodels>=0.8.0',
]
packages=['choicemodels'],
install_requires=install_requires
)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
13 changes: 13 additions & 0 deletions tests/test_choicemodels.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
def test_import():
import choicemodels

def test_simple_estimation():
import choicemodels
import numpy as np
import pandas as pd
from collections import OrderedDict
endog = np.random.randint(2, size=50)
exog = np.random.rand(50, 5)
m = choicemodels.Logit(endog, exog)
results = m.fit()
results.summary()
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pandas as pd
import pytest

from .. import interaction as inter
from choicemodels.tools import interaction as inter


@pytest.fixture
Expand Down
2 changes: 1 addition & 1 deletion choicemodels/tools/tests/test_mnl.py → tests/test_mnl.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import pytest
from patsy import dmatrix

from .. import mnl
from choicemodels import mnl


@pytest.fixture
Expand Down

0 comments on commit e8a3211

Please sign in to comment.