Extract results from Jupyter notebooks
Project description
nbresult
A simple package to test Jupyter notebook result for the Le Wagon's Data Science Bootcamp.
Installation
Installation with pip
from Pypi:
pip install nbresult
Usage
Considering the default data challenge architecture:
.
├── challenge.ipynb
├── Makefile
├── README.md
├── data
│ └── data.csv
└── tests
├── __init__.py
└── test_results.py
If you want to test a variable log_model_score
from the challenge.ipynb
notebook with pytest
:
At the end of the notebook add a cell with the following code:
from nbresult.challenge_result import ChallengeResult
RESULT = ChallengeResult(
score=log_model_score
)
RESULT.write()
This outputs a results.json
file in the tests
directory:
# tests/results.json
{
"score": 0.829004329004329
}
The notebook results can be imported from anywhere with:
from nbresult.challenge_result import ChallengeResult
results = ChallengeResult().load('path/to/results.json')
So you can write test the log_model_score
with pytest
:
# test_results.py
import unittest
import os
from nbresult.challenge_result import ChallengeResult
class TestResults(unittest.TestCase):
results = ChallengeResult().load(os.path.join(
os.path.dirname(__file__),
'results.json')
)
def test_model_score(self):
self.assertEqual(self.results['score'] > 0.82, True)
Finally you can run your tests with pytest
:
pytest tests/test_results.py
OR
Run the tests with make
:
- Setup a
Makefile
# Makefile
default: pytest
pytest:
PYTHONDONTWRITEBYTECODE=1 pytest -v --color=yes
- Run
make
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
nbresult-0.0.2.tar.gz
(2.4 kB
view hashes)