-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ebcb7d2
commit 6686e0d
Showing
7 changed files
with
189 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
.snakemake | ||
notebooks/ | ||
|
||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
env/ | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
|
||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
*.manifest | ||
*.spec | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
*,cover | ||
.hypothesis/ | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
# Django stuff: | ||
*.log | ||
local_settings.py | ||
|
||
# Flask stuff: | ||
instance/ | ||
.webassets-cache | ||
|
||
# Scrapy stuff: | ||
.scrapy | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# PyBuilder | ||
target/ | ||
|
||
# IPython Notebook | ||
.ipynb_checkpoints | ||
|
||
# pyenv | ||
.python-version | ||
|
||
# celery beat schedule file | ||
celerybeat-schedule | ||
|
||
# dotenv | ||
.env | ||
|
||
# virtualenv | ||
venv/ | ||
ENV/ | ||
|
||
# Spyder project settings | ||
.spyderproject | ||
|
||
# Rope project settings | ||
.ropeproject |
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import pytest | ||
import quantgov.estimator | ||
import subprocess | ||
|
||
from pathlib import Path | ||
|
||
|
||
PSEUDO_CORPUS_PATH = Path(__file__).resolve().parent.joinpath('pseudo_corpus') | ||
PSEUDO_ESTIMATOR_PATH = ( | ||
Path(__file__).resolve().parent | ||
.joinpath('pseudo_estimator') | ||
) | ||
|
||
|
||
def check_output(cmd): | ||
return ( | ||
subprocess.check_output(cmd, universal_newlines=True) | ||
.replace('\n\n', '\n') | ||
) | ||
|
||
|
||
def test_simple_estimator(): | ||
output = check_output( | ||
['quantgov', 'estimator', 'estimate', | ||
str(PSEUDO_ESTIMATOR_PATH.joinpath('data', 'vectorizer.pickle')), | ||
str(PSEUDO_ESTIMATOR_PATH.joinpath('data', 'model.pickle')), | ||
str(PSEUDO_CORPUS_PATH)] | ||
) | ||
assert output == 'file,is_world\ncfr,False\nmoby,False\n' | ||
|
||
|
||
def test_probability_estimator(): | ||
output = check_output( | ||
['quantgov', 'estimator', 'estimate', | ||
str(PSEUDO_ESTIMATOR_PATH.joinpath('data', 'vectorizer.pickle')), | ||
str(PSEUDO_ESTIMATOR_PATH.joinpath('data', 'model.pickle')), | ||
str(PSEUDO_CORPUS_PATH), '--probability'] | ||
) | ||
assert output == ('file,is_world_prob\ncfr,0.0899\nmoby,0.0216\n') | ||
|
||
|
||
def test_probability_estimator_6decimals(): | ||
output = check_output( | ||
['quantgov', 'estimator', 'estimate', | ||
str(PSEUDO_ESTIMATOR_PATH.joinpath('data', 'vectorizer.pickle')), | ||
str(PSEUDO_ESTIMATOR_PATH.joinpath('data', 'model.pickle')), | ||
str(PSEUDO_CORPUS_PATH), '--probability', '--precision', '6'] | ||
) | ||
assert output == ('file,is_world_prob\ncfr,0.089898\nmoby,0.02162\n') | ||
|
||
|
||
def test_multiclass_probability_estimator(): | ||
output = check_output( | ||
['quantgov', 'estimator', 'estimate', | ||
str(PSEUDO_ESTIMATOR_PATH.joinpath('data', 'vectorizer.pickle')), | ||
str(PSEUDO_ESTIMATOR_PATH.joinpath('data', 'modelmulticlass.pickle')), | ||
str(PSEUDO_CORPUS_PATH), '--probability'] | ||
) | ||
assert output == ('file,class,probability\n' | ||
'cfr,business-and-industry,0.1765\n' | ||
'cfr,environment,0.1294\n' | ||
'cfr,health-and-public-welfare,0.1785\n' | ||
'cfr,money,0.169\n' | ||
'cfr,science-and-technology,0.147\n' | ||
'cfr,world,0.1997\n' | ||
'moby,business-and-industry,0.1804\n' | ||
'moby,environment,0.1529\n' | ||
'moby,health-and-public-welfare,0.205\n' | ||
'moby,money,0.1536\n' | ||
'moby,science-and-technology,0.1671\n' | ||
'moby,world,0.141\n') |