├── .github ├── CODEOWNERS └── workflows │ └── pythonpackage.yml ├── .gitignore ├── .pre-commit-config.yaml ├── LICENSE ├── MANIFEST.in ├── Makefile ├── README.md ├── RELEASE_NOTES.md ├── data ├── .gitkeep ├── surv │ ├── flchain.csv │ ├── sprint-cut.csv │ └── support2.csv └── uci │ ├── kin8nm.csv │ ├── naval-propulsion.txt │ ├── power-plant.xlsx │ └── protein.csv ├── docs ├── 0-install.html ├── 1-useage.html ├── 2-tuning.html ├── 3-interpretation.html ├── 4-saving.html ├── 5-dev.html ├── Guardfile ├── Makefile ├── assets │ ├── css │ │ ├── style.css │ │ └── styles.css │ ├── custom │ │ ├── custom.css │ │ └── custom.js │ ├── images │ │ ├── download-solid.svg │ │ ├── edit-button.svg │ │ ├── list-solid.svg │ │ ├── logo_binder.svg │ │ ├── logo_jupyterhub.svg │ │ └── search-solid.svg │ └── js │ │ ├── page │ │ ├── anchors.js │ │ ├── copy-button.js │ │ ├── documentSelectors.js │ │ ├── dom-update.js │ │ ├── hide-cell.js │ │ └── tocbot.js │ │ └── scripts.js ├── content │ ├── 0-install.ipynb │ ├── 1-useage.ipynb │ ├── 2-tuning.ipynb │ ├── 3-interpretation.ipynb │ ├── 4-saving.ipynb │ ├── 5-dev.ipynb │ ├── LICENSE.md │ ├── features │ │ ├── cool.jpg │ │ ├── features.html │ │ ├── features.md │ │ ├── markdown.html │ │ ├── markdown.md │ │ └── notebooks.ipynb │ ├── images │ │ ├── C-3PO_droid.png │ │ └── logo │ │ │ ├── download.svg │ │ │ ├── favicon.ico │ │ │ ├── jupyter.png │ │ │ ├── logo.png │ │ │ └── logo.psd │ ├── intro.html │ └── intro.md ├── features │ └── cool.jpg ├── feed.xml ├── images │ ├── 3-interpretation_4_1.png │ ├── 3-interpretation_6_2.png │ ├── C-3PO_droid.png │ └── logo │ │ ├── download.svg │ │ ├── favicon.ico │ │ ├── jupyter.png │ │ ├── logo.png │ │ └── logo.psd ├── index.html ├── intro.html ├── redirects.json ├── requirements.txt ├── runtime.txt └── search.html ├── examples ├── __init__.py ├── classification.py ├── experiments │ ├── __init__.py │ ├── regression_exp.py │ └── survival_exp.py ├── model_interpretation │ ├── Feature_importance.ipynb │ └── SHAP_plots.ipynb ├── multiclass_classification.py ├── multivariate_normal.py ├── poisson.py ├── regression.py ├── simulations │ ├── __init__.py │ ├── regression_sim.py │ └── survival_sim.py ├── sklearn_cv.py ├── survival.py ├── tuning │ └── hyperopt.ipynb └── user-guide │ ├── Gemfile │ ├── Gemfile.lock │ ├── Guardfile │ ├── Makefile │ ├── _bibliography │ └── references.bib │ ├── _config.yml │ ├── _data │ └── toc.yml │ ├── _includes │ ├── buttons.html │ ├── buttons │ │ ├── binder.html │ │ ├── download.html │ │ ├── jupyterhub.html │ │ ├── nbinteract.html │ │ └── thebelab.html │ ├── css_entry.scss │ ├── fb_tags.html │ ├── footer.html │ ├── google_analytics.html │ ├── head.html │ ├── js │ │ ├── interact-update.html │ │ ├── nbinteract.html │ │ ├── print.html │ │ ├── thebelab-cell-button.html │ │ ├── thebelab-page-config.html │ │ └── thebelab.html │ ├── mathjax.html │ ├── metadata.json │ ├── page-nav.html │ ├── search │ │ └── lunr │ │ │ ├── lunr-en.js │ │ │ └── lunr-store.js │ ├── sidebar.html │ └── topbar.html │ ├── _layouts │ └── default.html │ ├── _sass │ ├── components │ │ ├── _components.book__layout.scss │ │ ├── _components.book__topbar.scss │ │ ├── _components.interact-button.scss │ │ ├── _components.page__footer.scss │ │ ├── _components.page__nav.scss │ │ ├── _components.page__onthispage.scss │ │ ├── _components.search.scss │ │ └── _components.thebelab.scss │ ├── hamburgers │ │ ├── _base.scss │ │ ├── hamburgers.scss │ │ └── types │ │ │ └── _arrowalt.scss │ ├── main.scss │ ├── objects │ │ └── _objects.thebelab-in-cell-button.scss │ └── page │ │ ├── components │ │ ├── _components.hidecells.scss │ │ ├── _components.page.scss │ │ └── _components.sidebar-right.scss │ │ ├── elements │ │ ├── _elements.links.scss │ │ ├── _elements.syntax-highlighting.scss │ │ ├── _elements.tables.scss │ │ ├── _elements.typography.scss │ │ └── _elements.variables.scss │ │ ├── generic │ │ └── _generic.phone-scrolling.scss │ │ ├── inuitcss │ │ ├── elements │ │ │ ├── _elements.headings.scss │ │ │ ├── _elements.images.scss │ │ │ ├── _elements.page.scss │ │ │ └── _elements.tables.scss │ │ ├── generic │ │ │ ├── _generic.box-sizing.scss │ │ │ ├── _generic.normalize.scss │ │ │ ├── _generic.reset.scss │ │ │ └── _generic.shared.scss │ │ ├── objects │ │ │ ├── _objects.block.scss │ │ │ ├── _objects.box.scss │ │ │ ├── _objects.crop.scss │ │ │ ├── _objects.flag.scss │ │ │ ├── _objects.layout.scss │ │ │ ├── _objects.list-bare.scss │ │ │ ├── _objects.list-inline.scss │ │ │ ├── _objects.media.scss │ │ │ ├── _objects.pack.scss │ │ │ ├── _objects.ratio.scss │ │ │ ├── _objects.table.scss │ │ │ └── _objects.wrapper.scss │ │ ├── settings │ │ │ ├── _example.settings.config.scss │ │ │ ├── _example.settings.global.scss │ │ │ └── _settings.core.scss │ │ ├── tools │ │ │ ├── _tools.clearfix.scss │ │ │ ├── _tools.font-size.scss │ │ │ ├── _tools.hidden.scss │ │ │ └── _tools.mq.scss │ │ └── utilities │ │ │ ├── _utilities.clearfix.scss │ │ │ ├── _utilities.headings.scss │ │ │ ├── _utilities.hide.scss │ │ │ ├── _utilities.print.scss │ │ │ ├── _utilities.responsive-spacings.scss │ │ │ ├── _utilities.spacings.scss │ │ │ └── _utilities.widths.scss │ │ ├── main.scss │ │ ├── objects │ │ ├── _objects.copy-button.scss │ │ └── _objects.tooltip.scss │ │ └── settings │ │ └── settings.global.scss │ ├── assets │ ├── css │ │ └── styles.scss │ ├── custom │ │ ├── custom.css │ │ └── custom.js │ ├── html │ │ ├── index.html │ │ └── search_form.html │ ├── images │ │ ├── download-solid.svg │ │ ├── edit-button.svg │ │ ├── list-solid.svg │ │ ├── logo_binder.svg │ │ ├── logo_jupyterhub.svg │ │ └── search-solid.svg │ └── js │ │ ├── page │ │ ├── anchors.js │ │ ├── copy-button.js │ │ ├── documentSelectors.js │ │ ├── dom-update.js │ │ ├── hide-cell.js │ │ └── tocbot.js │ │ └── scripts.js │ ├── content │ ├── 0-install.ipynb │ ├── 1-useage.ipynb │ ├── 2-tuning.ipynb │ ├── 3-interpretation.ipynb │ ├── 4-saving.ipynb │ ├── 5-dev.ipynb │ ├── LICENSE.md │ ├── features │ │ ├── cool.jpg │ │ ├── features.md │ │ ├── markdown.md │ │ └── notebooks.ipynb │ ├── images │ │ ├── C-3PO_droid.png │ │ └── logo │ │ │ ├── download.svg │ │ │ ├── favicon.ico │ │ │ ├── jupyter.png │ │ │ ├── logo.png │ │ │ └── logo.psd │ └── intro.md │ ├── requirements.txt │ ├── runtime.txt │ └── scripts │ └── clean.py ├── figures ├── anim │ ├── toy0.pdf │ ├── toy0.png │ ├── toy10.png │ ├── toy100.png │ ├── toy12.png │ ├── toy120.png │ ├── toy14.png │ ├── toy140.png │ ├── toy16.png │ ├── toy160.png │ ├── toy18.png │ ├── toy180.png │ ├── toy2.png │ ├── toy20.png │ ├── toy200.png │ ├── toy22.png │ ├── toy220.png │ ├── toy24.png │ ├── toy240.png │ ├── toy26.png │ ├── toy260.png │ ├── toy28.png │ ├── toy280.png │ ├── toy30.png │ ├── toy300.png │ ├── toy32.png │ ├── toy320.png │ ├── toy34.png │ ├── toy340.png │ ├── toy36.png │ ├── toy360.png │ ├── toy38.png │ ├── toy380.png │ ├── toy4.png │ ├── toy40.png │ ├── toy400.pdf │ ├── toy400.png │ ├── toy42.png │ ├── toy44.png │ ├── toy46.png │ ├── toy48.png │ ├── toy50.png │ ├── toy52.png │ ├── toy54.png │ ├── toy56.png │ ├── toy58.png │ ├── toy6.png │ ├── toy60.png │ ├── toy62.png │ ├── toy64.png │ ├── toy66.png │ ├── toy68.png │ ├── toy70.png │ ├── toy8.png │ ├── toy80.png │ ├── toy_naive_0.pdf │ ├── toy_naive_100.pdf │ ├── toy_naive_200.pdf │ ├── toy_naive_300.pdf │ ├── toy_naive_400.pdf │ ├── toy_natural_0.pdf │ ├── toy_natural_100.pdf │ ├── toy_natural_200.pdf │ ├── toy_natural_300.pdf │ └── toy_single.pdf ├── feat_importance.png ├── feature_importance.png ├── shap.png ├── shap_0.png ├── shap_1.png ├── toy.gif ├── toy.py ├── toy_single.py ├── vis_crps.pdf ├── vis_crps.py ├── vis_mle.pdf └── vis_mle.py ├── ngboost ├── __init__.py ├── api.py ├── distns │ ├── __init__.py │ ├── categorical.py │ ├── cauchy.py │ ├── distn.py │ ├── exponential.py │ ├── gamma.py │ ├── halfnormal.py │ ├── laplace.py │ ├── lognormal.py │ ├── multivariate_normal.py │ ├── normal.py │ ├── poisson.py │ ├── t.py │ ├── utils.py │ └── weibull.py ├── evaluation.py ├── helpers.py ├── learners.py ├── manifold.py ├── ngboost.py └── scores.py ├── pyproject.toml ├── pytest.ini ├── results └── .gitkeep ├── scripts ├── run_empirical_regression.sh ├── run_empirical_regression_homosk.sh ├── run_empirical_regression_ordinary.sh └── run_empirical_survival.sh ├── setup.cfg ├── tests ├── __init__.py ├── conftest.py ├── test_basic.py ├── test_distns.py ├── test_pickling.py ├── test_score.py └── test_version.py └── tox.ini /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | * ryan-wolbeck alejandroschuler tonyduan 2 | -------------------------------------------------------------------------------- /.github/workflows/pythonpackage.yml: -------------------------------------------------------------------------------- 1 | name: Python lint and test 2 | 3 | on: 4 | push: 5 | pull_request: 6 | branches: 7 | - master 8 | 9 | jobs: 10 | build: 11 | runs-on: ubuntu-latest 12 | strategy: 13 | matrix: 14 | python-version: ['3.9', '3.10', '3.11', '3.12'] 15 | 16 | steps: 17 | - uses: actions/checkout@v2 18 | - name: Set up Python ${{ matrix.python-version }} 19 | uses: actions/setup-python@v1 20 | with: 21 | python-version: ${{ matrix.python-version }} 22 | - name: Install dependencies 23 | run: make install 24 | - name: Run linters 25 | run: make lint 26 | - name: Run tests 27 | run: make test 28 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Pycharm 2 | .idea/ 3 | 4 | # Byte-compiled / optimized / DLL files 5 | __pycache__/ 6 | *.py[cod] 7 | *$py.class 8 | 9 | # C extensions 10 | *.so 11 | 12 | # Distribution / packaging .Python 13 | build/ 14 | develop-eggs/ 15 | dist/ 16 | downloads/ 17 | eggs/ 18 | .eggs/ 19 | examples/user-guide/_build/ 20 | examples/user-guide/.sass-cache/ 21 | lib/ 22 | lib64/ 23 | parts/ 24 | sdist/ 25 | var/ 26 | wheels/ 27 | *.egg-info/ 28 | .installed.cfg 29 | *.egg 30 | MANIFEST 31 | 32 | # PyInstaller 33 | # Usually these files are written by a python script from a template 34 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 35 | *.manifest 36 | *.spec 37 | 38 | # Installer logs 39 | pip-log.txt 40 | pip-delete-this-directory.txt 41 | 42 | # Unit test / coverage reports 43 | htmlcov/ 44 | .tox/ 45 | .coverage 46 | .coverage.* 47 | .cache 48 | nosetests.xml 49 | coverage.xml 50 | *.cover 51 | .hypothesis/ 52 | .pytest_cache/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | 63 | # Flask stuff: 64 | instance/ 65 | .webassets-cache 66 | 67 | # Scrapy stuff: 68 | .scrapy 69 | 70 | # Sphinx documentation 71 | docs/_build/ 72 | 73 | # PyBuilder 74 | target/ 75 | 76 | # Jupyter Notebook 77 | .ipynb_checkpoints 78 | 79 | # pyenv 80 | .python-version 81 | 82 | # celery beat schedule file 83 | celerybeat-schedule 84 | 85 | # SageMath parsed files 86 | *.sage.py 87 | 88 | # Environments 89 | .env 90 | .venv 91 | env/ 92 | venv/ 93 | ENV/ 94 | env.bak/ 95 | venv.bak/ 96 | 97 | # Spyder project settings 98 | .spyderproject 99 | .spyproject 100 | 101 | # Rope project settings 102 | .ropeproject 103 | 104 | # mkdocs documentation 105 | /site 106 | 107 | # mypy 108 | .mypy_cache/ 109 | 110 | # Get rid of data 111 | *.swp 112 | *.pkl 113 | 114 | .DS_Store 115 | poetry.lock 116 | -------------------------------------------------------------------------------- /.pre-commit-config.yaml: -------------------------------------------------------------------------------- 1 | # See https://pre-commit.com for more information 2 | # See https://pre-commit.com/hooks.html for more hooks 3 | 4 | default_stages: [commit, manual] 5 | 6 | repos: 7 | - repo: https://github.com/pre-commit/pre-commit-hooks 8 | rev: v2.2.3 9 | hooks: 10 | - id: trailing-whitespace 11 | - id: end-of-file-fixer 12 | - id: check-yaml # Checks yaml files for parsable syntax. 13 | - id: check-json # Checks json files for parsable syntax. 14 | - id: check-added-large-files # Checks for large files that bloat the git repository 15 | - id: check-case-conflict # Check for files that would conflict in case-insensitive filesystems 16 | - id: check-merge-conflict # Check for files that contain merge conflict strings. 17 | - id: debug-statements # Check for debugger imports and py37+ `breakpoint()` calls in python source. 18 | - repo: https://github.com/psf/black 19 | rev: 22.8.0 20 | hooks: 21 | - id: black 22 | - repo: local 23 | hooks: 24 | - id: isort 25 | name: isort 26 | types: [file, python] 27 | language: system 28 | entry: isort 29 | - id: flake8 30 | name: Flake8 31 | types: [file, python] 32 | language: system 33 | files: ^ngboost 34 | entry: flake8 35 | - id: pylint-ngboost 36 | name: pylint on ngboost* 37 | types: [file, python] 38 | language: system 39 | files: ^ngboost 40 | entry: pylint --disable=invalid-name,no-member,missing-docstring,no-self-argument,arguments-differ 41 | - id: pylint-tests 42 | name: pylint on tests* 43 | language: system 44 | files: ^tests 45 | entry: pylint --disable=invalid-name,missing-docstring,too-many-function-args,unused-variable,fixme 46 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include LICENSE 2 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | 2 | install: 3 | pip install poetry==2.0.1 && poetry install 4 | 5 | package: 6 | poetry build 7 | 8 | publish: package 9 | source .env && poetry config pypi-token.pypi $$PYPI_TOKEN && poetry publish 10 | 11 | lint: 12 | poetry run pre-commit run --hook-stage manual --all-files 13 | 14 | test: 15 | poetry run pytest --slow -v 16 | 17 | clean: 18 | rm -rf dist/* 19 | -------------------------------------------------------------------------------- /RELEASE_NOTES.md: -------------------------------------------------------------------------------- 1 | # RELEASE NOTES 2 | 3 | ## Version 0.5.5 4 | 5 | * Add support for Weibull and HalfNormal Distributions 6 | 7 | ## Version 0.5.5 8 | 9 | * Upgrade sklearn > 1.6 10 | 11 | ## Version 0.5.4 12 | 13 | * Update to partial fit to respect validation data 14 | 15 | ## Version 0.5.3 16 | 17 | * Allow NAN as input 18 | * Poetry update 19 | 20 | ## Version 0.5.2 21 | 22 | * Support for Numpy 2.0 23 | * Value error fix 24 | * Linting updates 25 | 26 | ## Version 0.5.1 27 | 28 | * Adds support for NormalFixedMean distribution 29 | * Updates to makefile for easier publishing 30 | 31 | ## Version 0.5.0 32 | 33 | * Drops support for python 3.7 and 3.8 34 | * Now supports Python 3.11 and 3.12 35 | * Fixed issue with np.bool 36 | * Optimized memory usage in pred-dist 37 | * Removed declared pandas dependency 38 | * Significant improvements to run times on tests during development 39 | * Minor enhancements to github actions 40 | 41 | ## Version 0.4.2 42 | 43 | * Fix deprecated numpy type alias. This was causing a warning with NumPy >=1.20 and an error with NumPy >=1.24 44 | * Remove pandas as a declared dependency 45 | 46 | ## Version 0.4.1 47 | 48 | ### Added `partial_fit` method for incremental learning 49 | 50 | NGBoost now includes a new `partial_fit` method that allows for incremental learning. This method appends new base models to the existing ones, which can be useful when new data becomes available over time or when the data is too large to fit in memory all at once. 51 | 52 | The `partial_fit` method takes similar parameters to the `fit` method, including predictors `X`, outcomes `Y`, and validation sets `X_val` and `Y_val`. It also supports custom weights for the training and validation sets, as well as early stopping and custom loss monitoring. 53 | 54 | Please note that the `partial_fit` method is not yet fully tested and may not work as expected in all cases. Use it with caution and thoroughly test its behavior in your specific use case before relying on it in production. 55 | 56 | ## Version 0.4.0 57 | 58 | * Added support for the gamma distribution 59 | * Added sklearn support to `set_params` 60 | * Fixed off-by-one issue for max trees 61 | * Upgraded version of `black` formatter to 22.8.0 62 | -------------------------------------------------------------------------------- /data/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stanfordmlgroup/ngboost/10d67107f32e0dc047ada38de85645bb9b2fd4c8/data/.gitkeep -------------------------------------------------------------------------------- /data/uci/power-plant.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stanfordmlgroup/ngboost/10d67107f32e0dc047ada38de85645bb9b2fd4c8/data/uci/power-plant.xlsx -------------------------------------------------------------------------------- /docs/Guardfile: -------------------------------------------------------------------------------- 1 | guard 'jekyll-plus', serve: true do 2 | watch /.*/ 3 | ignore /^_site/ 4 | end 5 | 6 | guard 'livereload' do 7 | watch /.*/ 8 | end 9 | -------------------------------------------------------------------------------- /docs/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: help book clean serve 2 | 3 | help: 4 | @echo "Please use 'make ' where is one of:" 5 | @echo " install to install the necessary dependencies for jupyter-book to build" 6 | @echo " book to convert the content/ folder into Jekyll markdown in _build/" 7 | @echo " clean to clean out site build files" 8 | @echo " runall to run all notebooks in-place, capturing outputs with the notebook" 9 | @echo " serve to serve the repository locally with Jekyll" 10 | @echo " build to build the site HTML and store in _build/" 11 | @echo " site to build the site HTML, store in _site/, and serve with Jekyll" 12 | 13 | 14 | install: 15 | jupyter-book install ./ 16 | 17 | book: 18 | jupyter-book build ./ 19 | 20 | runall: 21 | jupyter-book run ./content 22 | 23 | clean: 24 | python scripts/clean.py 25 | 26 | serve: 27 | bundle exec guard 28 | 29 | build: 30 | jupyter-book build ./ --overwrite 31 | 32 | site: build 33 | bundle exec jekyll build 34 | touch _site/.nojekyll 35 | -------------------------------------------------------------------------------- /docs/assets/custom/custom.css: -------------------------------------------------------------------------------- 1 | /* Put your custom CSS here */ 2 | .left { 3 | margin: 5px 2px 2px 0px !important; 4 | float: left !important; 5 | } 6 | -------------------------------------------------------------------------------- /docs/assets/custom/custom.js: -------------------------------------------------------------------------------- 1 | // Put your custom javascript here 2 | -------------------------------------------------------------------------------- /docs/assets/images/download-solid.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 8 | 13 | 14 | -------------------------------------------------------------------------------- /docs/assets/images/edit-button.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 8 | 13 | 14 | -------------------------------------------------------------------------------- /docs/assets/images/list-solid.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 8 | 14 | 15 | -------------------------------------------------------------------------------- /docs/assets/images/logo_binder.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 10 | logo 11 | 12 | 13 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /docs/assets/images/logo_jupyterhub.svg: -------------------------------------------------------------------------------- 1 | logo_jupyterhubHub 2 | -------------------------------------------------------------------------------- /docs/assets/images/search-solid.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 8 | 12 | 13 | -------------------------------------------------------------------------------- /docs/assets/js/page/anchors.js: -------------------------------------------------------------------------------- 1 | const initAnchors = () => { 2 | if (window.anchors === undefined) { 3 | setTimeout(initAnchors, 250); 4 | return; 5 | } 6 | anchors.add("main h1, main h2, main h3, main h4"); 7 | 8 | // Disable Turbolinks for anchors 9 | document.querySelectorAll('.anchorjs-link') 10 | .forEach(it => it.dataset['turbolinks'] = false); 11 | } 12 | initFunction(initAnchors); 13 | -------------------------------------------------------------------------------- /docs/assets/js/page/copy-button.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Set up copy/paste for code blocks 3 | */ 4 | const copySVG = `` 8 | 9 | const clipboardButton = id => 10 | ` 11 | ${copySVG} 12 | ` 13 | 14 | // Clears selected text since ClipboardJS will select the text when copying 15 | const clearSelection = () => { 16 | if (window.getSelection) { 17 | window.getSelection().removeAllRanges() 18 | } else if (document.selection) { 19 | document.selection.empty() 20 | } 21 | } 22 | 23 | // Changes tooltip text for two seconds, then changes it back 24 | const temporarilyChangeTooltip = (el, newText) => { 25 | const oldText = el.getAttribute('data-tooltip') 26 | el.setAttribute('data-tooltip', newText) 27 | setTimeout(() => el.setAttribute('data-tooltip', oldText), 2000) 28 | } 29 | 30 | const addCopyButtonToCodeCells = () => { 31 | // If ClipboardJS hasn't loaded, wait a bit and try again. This 32 | // happens because we load ClipboardJS asynchronously. 33 | if (window.ClipboardJS === undefined) { 34 | setTimeout(addCopyButtonToCodeCells, 250) 35 | return 36 | } 37 | 38 | pageElements['codeCells'].forEach((codeCell) => { 39 | const id = codeCell.getAttribute('id') 40 | if (document.getElementById("copy-button" + id) == null) { 41 | codeCell.insertAdjacentHTML('afterend', clipboardButton(id)); 42 | } 43 | }) 44 | 45 | const clipboard = new ClipboardJS('.copybtn') 46 | clipboard.on('success', event => { 47 | clearSelection() 48 | temporarilyChangeTooltip(event.trigger, 'Copied!') 49 | }) 50 | 51 | clipboard.on('error', event => { 52 | temporarilyChangeTooltip(event.trigger, 'Failed to copy') 53 | }) 54 | 55 | // Get rid of clipboard before the next page visit to avoid memory leak 56 | document.addEventListener('turbolinks:before-visit', () => 57 | clipboard.destroy() 58 | ) 59 | } 60 | 61 | initFunction(addCopyButtonToCodeCells); 62 | -------------------------------------------------------------------------------- /docs/assets/js/page/documentSelectors.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Select various elements on the page for later use 3 | */ 4 | 5 | // IDs we'll attach to cells 6 | const codeCellId = index => `codecell${index}` 7 | const inputCellId = index => `inputcell${index}` 8 | 9 | pageElements = {} 10 | 11 | // All code cells 12 | findCodeCells = function() { 13 | var codeCells = document.querySelectorAll('div.c-textbook__content > div.highlighter-rouge > div.highlight > pre, div.input_area pre, div.text_cell_render div.highlight pre') 14 | pageElements['codeCells'] = codeCells; 15 | 16 | codeCells.forEach((codeCell, index) => { 17 | const id = codeCellId(index) 18 | codeCell.setAttribute('id', id) 19 | }) 20 | }; 21 | 22 | initFunction(findCodeCells); 23 | 24 | // All cells in general 25 | findInputCells = function() { 26 | var inputCells = document.querySelectorAll('div.jb_cell') 27 | pageElements['inputCells'] = inputCells; 28 | 29 | inputCells.forEach((inputCell, index) => { 30 | const id = inputCellId(index) 31 | inputCell.setAttribute('id', id) 32 | }) 33 | }; 34 | 35 | initFunction(findInputCells); 36 | -------------------------------------------------------------------------------- /docs/assets/js/page/dom-update.js: -------------------------------------------------------------------------------- 1 | const runWhenDOMLoaded = cb => { 2 | if (document.readyState != 'loading') { 3 | cb() 4 | } else if (document.addEventListener) { 5 | document.addEventListener('DOMContentLoaded', cb) 6 | } else { 7 | document.attachEvent('onreadystatechange', function() { 8 | if (document.readyState == 'complete') cb() 9 | }) 10 | } 11 | } 12 | 13 | // Helper function to init things quickly 14 | initFunction = function(myfunc) { 15 | runWhenDOMLoaded(myfunc); 16 | document.addEventListener('turbolinks:load', myfunc); 17 | }; 18 | -------------------------------------------------------------------------------- /docs/assets/js/page/hide-cell.js: -------------------------------------------------------------------------------- 1 | /** 2 | Add buttons to hide code cells 3 | */ 4 | var setCellVisibility = function (inputField, kind) { 5 | // Update the image and class for hidden 6 | var id = inputField.getAttribute('data-id'); 7 | var element = document.querySelector(`#${id}`); 8 | 9 | if (kind === "visible") { 10 | element.classList.remove('hidden'); 11 | inputField.checked = true; 12 | } else { 13 | element.classList.add('hidden'); 14 | inputField.checked = false; 15 | } 16 | } 17 | 18 | var toggleCellVisibility = function (event) { 19 | // The label is clicked, and now we decide what to do based on the input field's clicked status 20 | if (event.target.tagName === "LABEL") { 21 | var inputField = event.target.previousElementSibling; 22 | } else { 23 | // It is the span inside the target 24 | var inputField = event.target.parentElement.previousElementSibling; 25 | } 26 | 27 | if (inputField.checked === true) { 28 | setCellVisibility(inputField, "visible"); 29 | } else { 30 | setCellVisibility(inputField, "hidden"); 31 | } 32 | } 33 | 34 | 35 | // Button constructor 36 | const hideCodeButton = id => `` 37 | 38 | var addHideButton = (element, id) => { 39 | // Add a hide button to an HTML element. 40 | element.setAttribute("id", id) 41 | // Insert the button just inside the end of the next div 42 | element.insertAdjacentHTML('afterend', hideCodeButton(id)) 43 | 44 | // Set up the visibility toggle 45 | // The label will be two-sibings deep from the element to-be hidden 46 | hideLink = element.nextElementSibling.nextElementSibling; 47 | hideLink.addEventListener('click', toggleCellVisibility) 48 | } 49 | 50 | var addAllHideButtons = function () { 51 | // If a hide button is already added, don't add another 52 | if (document.querySelector('input.hidebtn') !== null) { 53 | return; 54 | } 55 | 56 | // Find the input cells and add a hide button 57 | hideIdNum = 0; 58 | pageElements['inputCells'].forEach((cell) => { 59 | const id = cell.getAttribute('id') 60 | 61 | if (cell.classList.contains("tag_hide_input")) { 62 | addHideButton(cell.querySelector('div.inner_cell'), `hide-${hideIdNum}`); 63 | hideIdNum ++; 64 | } 65 | 66 | if (cell.classList.contains("tag_hide_output")) { 67 | addHideButton(cell.querySelector('div.output'), `hide-${hideIdNum}`); 68 | hideIdNum ++; 69 | } 70 | }); 71 | } 72 | 73 | 74 | // Initialize the hide buttos 75 | var initHiddenCells = function () { 76 | // Add hide buttons to the cells 77 | addAllHideButtons(); 78 | 79 | // Toggle the code cells that should be hidden 80 | document.querySelectorAll('div.tag_hide_input input, div.tag_hide_output input').forEach(function (item) { 81 | setCellVisibility(item, 'hidden'); 82 | item.checked = true; 83 | }) 84 | } 85 | 86 | initFunction(initHiddenCells); 87 | -------------------------------------------------------------------------------- /docs/assets/js/page/tocbot.js: -------------------------------------------------------------------------------- 1 | const initToc = () => { 2 | if (window.tocbot === undefined) { 3 | setTimeout(initToc, 250); 4 | return; 5 | } 6 | 7 | // Check whether we have any sidebar content. If not, then show the sidebar earlier. 8 | var SIDEBAR_CONTENT_TAGS = ['.tag_full_width', '.tag_popout']; 9 | var sidebar_content_query = SIDEBAR_CONTENT_TAGS.join(', ') 10 | if (document.querySelectorAll(sidebar_content_query).length === 0) { 11 | document.querySelector('nav.onthispage').classList.add('no_sidebar_content') 12 | } 13 | 14 | // Initialize the TOC bot if we have TOC headers 15 | const tocContent = '.c-textbook__content'; 16 | const tocHeaders = 'h1, h2, h3'; 17 | var headers = document.querySelector(tocContent).querySelectorAll(tocHeaders); 18 | if (headers.length > 0) { 19 | document.querySelector('aside.sidebar__right').classList.remove('hidden'); 20 | tocbot.init({ 21 | tocSelector: 'nav.onthispage', 22 | contentSelector: tocContent, 23 | headingSelector: tocHeaders, 24 | orderedList: false, 25 | collapseDepth: 6, 26 | listClass: 'toc__menu', 27 | activeListItemClass: " ", // Not using, can't be empty 28 | activeLinkClass: " ", // Not using, can't be empty 29 | }); 30 | } else { 31 | document.querySelector('aside.sidebar__right').classList.add('hidden'); 32 | } 33 | 34 | // Disable Turbolinks for TOC links 35 | document.querySelectorAll('.toc-list-item a') 36 | .forEach(it => it.dataset['turbolinks'] = false); 37 | } 38 | initFunction(initToc); 39 | -------------------------------------------------------------------------------- /docs/content/0-install.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Installation\n", 8 | "\n", 9 | "NGBoost is easy to install using pip:\n", 10 | "\n", 11 | "```\n", 12 | "pip install --upgrade ngboost\n", 13 | "```\n", 14 | "\n", 15 | "although we recommend installing the most up-to-date version from github:\n", 16 | "\n", 17 | "```\n", 18 | "pip install --upgrade git+https://github.com/stanfordmlgroup/ngboost.git\n", 19 | "```" 20 | ] 21 | } 22 | ], 23 | "metadata": { 24 | "kernelspec": { 25 | "display_name": "Python 3", 26 | "language": "python", 27 | "name": "python3" 28 | }, 29 | "language_info": { 30 | "codemirror_mode": { 31 | "name": "ipython", 32 | "version": 3 33 | }, 34 | "file_extension": ".py", 35 | "mimetype": "text/x-python", 36 | "name": "python", 37 | "nbconvert_exporter": "python", 38 | "pygments_lexer": "ipython3", 39 | "version": "3.7.7" 40 | } 41 | }, 42 | "nbformat": 4, 43 | "nbformat_minor": 4 44 | } 45 | -------------------------------------------------------------------------------- /docs/content/LICENSE.md: -------------------------------------------------------------------------------- 1 | # License for this book 2 | 3 | All content in this book (ie, any files and content in the `content/` folder) 4 | is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International](https://creativecommons.org/licenses/by-sa/4.0/) 5 | (CC BY-SA 4.0) license. 6 | -------------------------------------------------------------------------------- /docs/content/features/cool.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stanfordmlgroup/ngboost/10d67107f32e0dc047ada38de85645bb9b2fd4c8/docs/content/features/cool.jpg -------------------------------------------------------------------------------- /docs/content/features/features.md: -------------------------------------------------------------------------------- 1 | # Features 2 | 3 | This is a short demonstration textbook to show the general layout / style of textbooks built 4 | with Jupyter and Jekyll. The markdown files for *this* page (and others in the textbook) is generated from the notebooks 5 | with the `scripts/generate_textbook.py` script, which is called when you run `make book`. 6 | 7 | The content for the book is contained in a folder in the book's repository called `content/`. It has a 8 | combination of markdown and Jupyter notebooks. This content is rendered into the textbook that you see here! 9 | 10 | To begin, click on one of the chapter sections in the sidebar to the left. The first section demonstrates some 11 | simple functionality of this repository, while the following chapters contain a subset of content from the 12 | [Foundations in Data Science](https://inferentialthinking.com). 13 | 14 | ## Quickstart 15 | 16 | This chapter shows a couple ways to add content to your course textbook. Click on the section headers 17 | to the left, or on the "next" button below in order to read further. 18 | -------------------------------------------------------------------------------- /docs/content/features/markdown.md: -------------------------------------------------------------------------------- 1 | # Creating book content 2 | 3 | The two kinds of files that contain course content are: 4 | 5 | * Jupyter Notebooks 6 | * Markdown files 7 | 8 | Each are contained in the `content/` folder and referenced from `_data/toc.yml`. 9 | 10 | If the file is markdown, it will be copied over with front-matter YAML added so 11 | that Jekyll can parse it 12 | 13 | ## Sidebars with Jekyll 14 | 15 | You may notice that there's a sidebar to the right (if your screen is wide enough). 16 | These are automatically generated from the headers that are present in your page. 17 | The sidebar will automatically capture all 2nd and 3rd level section headers. 18 | The best way to designate these headers is with `#` characters at the beginning 19 | of a line. 20 | 21 | ### Here's a third-level header 22 | 23 | This section is here purely to demonstrate the third-level header of the 24 | rendered page! 25 | 26 | ## Embedding media 27 | 28 | ### Adding images 29 | 30 | You can reference external media like images from your markdown file. If you use 31 | relative paths, then they will continue to work when the markdown files are copied over, 32 | so long as they point to a file that's inside of the repository. 33 | 34 | Here's an image relative to the site root 35 | 36 | ![](../images/C-3PO_droid.png) 37 | 38 | ### Adding movies 39 | 40 | You can even embed references to movies on the web! For example, here's a little gif for you! 41 | 42 | ![](https://media.giphy.com/media/yoJC2A59OCZHs1LXvW/giphy.gif) 43 | 44 | This will be included in your website when it is built. 45 | -------------------------------------------------------------------------------- /docs/content/images/C-3PO_droid.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stanfordmlgroup/ngboost/10d67107f32e0dc047ada38de85645bb9b2fd4c8/docs/content/images/C-3PO_droid.png -------------------------------------------------------------------------------- /docs/content/images/logo/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stanfordmlgroup/ngboost/10d67107f32e0dc047ada38de85645bb9b2fd4c8/docs/content/images/logo/favicon.ico -------------------------------------------------------------------------------- /docs/content/images/logo/jupyter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stanfordmlgroup/ngboost/10d67107f32e0dc047ada38de85645bb9b2fd4c8/docs/content/images/logo/jupyter.png -------------------------------------------------------------------------------- /docs/content/images/logo/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stanfordmlgroup/ngboost/10d67107f32e0dc047ada38de85645bb9b2fd4c8/docs/content/images/logo/logo.png -------------------------------------------------------------------------------- /docs/content/images/logo/logo.psd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stanfordmlgroup/ngboost/10d67107f32e0dc047ada38de85645bb9b2fd4c8/docs/content/images/logo/logo.psd -------------------------------------------------------------------------------- /docs/content/intro.md: -------------------------------------------------------------------------------- 1 | Welcome to the NGBoost user guide! 2 | 3 | Details on available distributions, scoring rules, learners, tuning, and model interpretation are available here, as are numerous usage examples. Please see the development section for more information on how to add new distributions or scores to NGBoost. 4 | 5 | If you have any problems or questions, feel free to [open an issue](https://github.com/stanfordmlgroup/ngboost/issues/new). 6 | -------------------------------------------------------------------------------- /docs/features/cool.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stanfordmlgroup/ngboost/10d67107f32e0dc047ada38de85645bb9b2fd4c8/docs/features/cool.jpg -------------------------------------------------------------------------------- /docs/feed.xml: -------------------------------------------------------------------------------- 1 | Jekyll2020-10-26T17:07:05-05:00https://stanfordmlgroup.github.io/ngboost/feed.xmlNGBoost User GuideNGBoost useage and developmentAlejandro Schuler 2 | -------------------------------------------------------------------------------- /docs/images/3-interpretation_4_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stanfordmlgroup/ngboost/10d67107f32e0dc047ada38de85645bb9b2fd4c8/docs/images/3-interpretation_4_1.png -------------------------------------------------------------------------------- /docs/images/3-interpretation_6_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stanfordmlgroup/ngboost/10d67107f32e0dc047ada38de85645bb9b2fd4c8/docs/images/3-interpretation_6_2.png -------------------------------------------------------------------------------- /docs/images/C-3PO_droid.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stanfordmlgroup/ngboost/10d67107f32e0dc047ada38de85645bb9b2fd4c8/docs/images/C-3PO_droid.png -------------------------------------------------------------------------------- /docs/images/logo/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stanfordmlgroup/ngboost/10d67107f32e0dc047ada38de85645bb9b2fd4c8/docs/images/logo/favicon.ico -------------------------------------------------------------------------------- /docs/images/logo/jupyter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stanfordmlgroup/ngboost/10d67107f32e0dc047ada38de85645bb9b2fd4c8/docs/images/logo/jupyter.png -------------------------------------------------------------------------------- /docs/images/logo/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stanfordmlgroup/ngboost/10d67107f32e0dc047ada38de85645bb9b2fd4c8/docs/images/logo/logo.png -------------------------------------------------------------------------------- /docs/images/logo/logo.psd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stanfordmlgroup/ngboost/10d67107f32e0dc047ada38de85645bb9b2fd4c8/docs/images/logo/logo.psd -------------------------------------------------------------------------------- /docs/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | Redirecting… 12 | 13 | 14 | 15 | 16 |

Redirecting…

17 | Click here if you are not redirected. 18 | 19 | -------------------------------------------------------------------------------- /docs/redirects.json: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /docs/requirements.txt: -------------------------------------------------------------------------------- 1 | # Requirements for the demo notebooks 2 | # Useful for MyBinder configuration 3 | pandas 4 | numpy 5 | datascience 6 | folium 7 | matplotlib 8 | nbinteract 9 | scipy 10 | jupyter-book 11 | -------------------------------------------------------------------------------- /docs/runtime.txt: -------------------------------------------------------------------------------- 1 | 3.7 2 | -------------------------------------------------------------------------------- /examples/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stanfordmlgroup/ngboost/10d67107f32e0dc047ada38de85645bb9b2fd4c8/examples/__init__.py -------------------------------------------------------------------------------- /examples/classification.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | from sklearn.datasets import load_breast_cancer 3 | from sklearn.metrics import roc_auc_score 4 | from sklearn.model_selection import train_test_split 5 | 6 | from ngboost import NGBClassifier 7 | from ngboost.distns import Bernoulli 8 | 9 | if __name__ == "__main__": 10 | 11 | np.random.seed(12345) 12 | 13 | X, Y = load_breast_cancer(return_X_y=True) 14 | X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=0.2) 15 | 16 | ngb = NGBClassifier(Dist=Bernoulli) 17 | ngb.fit(X_train, Y_train) 18 | 19 | preds = ngb.pred_dist(X_test) 20 | print("ROC:", roc_auc_score(Y_test, preds.probs[1])) 21 | -------------------------------------------------------------------------------- /examples/experiments/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stanfordmlgroup/ngboost/10d67107f32e0dc047ada38de85645bb9b2fd4c8/examples/experiments/__init__.py -------------------------------------------------------------------------------- /examples/multiclass_classification.py: -------------------------------------------------------------------------------- 1 | from sklearn.datasets import load_breast_cancer 2 | from sklearn.model_selection import train_test_split 3 | 4 | from ngboost import NGBClassifier 5 | from ngboost.distns import k_categorical 6 | 7 | if __name__ == "__main__": 8 | 9 | X, y = load_breast_cancer(return_X_y=True) 10 | y[0:15] = 2 # artificially make this a 3-class problem instead of a 2-class problem 11 | X_train, X_test, Y_train, Y_test = train_test_split(X, y, test_size=0.2) 12 | 13 | ngb = NGBClassifier( 14 | Dist=k_categorical(3) 15 | ) # tell ngboost that there are 3 possible outcomes 16 | ngb.fit(X_train, Y_train) # Y should have only 3 values: {0,1,2} 17 | 18 | # predicted probabilities of class 0, 1, and 2 (columns) for each observation (row) 19 | preds = ngb.predict_proba(X_test) 20 | -------------------------------------------------------------------------------- /examples/regression.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import pandas as pd 3 | from sklearn.metrics import mean_squared_error 4 | from sklearn.model_selection import train_test_split 5 | 6 | from ngboost import NGBRegressor 7 | from ngboost.distns import Normal 8 | 9 | if __name__ == "__main__": 10 | # Load Boston housing dataset 11 | data_url = "http://lib.stat.cmu.edu/datasets/boston" 12 | raw_df = pd.read_csv(data_url, sep=r"\s+", skiprows=22, header=None) 13 | X = np.hstack([raw_df.values[::2, :], raw_df.values[1::2, :2]]) 14 | Y = raw_df.values[1::2, 2] 15 | 16 | X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=0.2) 17 | 18 | ngb = NGBRegressor(Dist=Normal).fit(X_train, Y_train) 19 | Y_preds = ngb.predict(X_test) 20 | Y_dists = ngb.pred_dist(X_test) 21 | 22 | # test Mean Squared Error 23 | test_MSE = mean_squared_error(Y_preds, Y_test) 24 | print("Test MSE", test_MSE) 25 | 26 | # test Negative Log Likelihood 27 | test_NLL = -Y_dists.logpdf(Y_test.flatten()).mean() 28 | print("Test NLL", test_NLL) 29 | -------------------------------------------------------------------------------- /examples/simulations/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stanfordmlgroup/ngboost/10d67107f32e0dc047ada38de85645bb9b2fd4c8/examples/simulations/__init__.py -------------------------------------------------------------------------------- /examples/simulations/regression_sim.py: -------------------------------------------------------------------------------- 1 | from argparse import ArgumentParser 2 | 3 | import numpy as np 4 | from matplotlib import pyplot as plt 5 | from sklearn.metrics import r2_score 6 | 7 | from ngboost.distns import Normal 8 | from ngboost.evaluation import * 9 | from ngboost.learners import default_linear_learner 10 | from ngboost.ngboost import NGBoost 11 | 12 | if __name__ == "__main__": 13 | 14 | argparser = ArgumentParser() 15 | argparser.add_argument("--lr", type=float, default=0.1) 16 | argparser.add_argument("--dataset", type=str, default="simulated") 17 | argparser.add_argument("--noise-lvl", type=float, default=0.25) 18 | argparser.add_argument("--distn", type=str, default="Normal") 19 | argparser.add_argument("--natural", action="store_true") 20 | argparser.add_argument("--score", type=str, default="CRPS") 21 | args = argparser.parse_args() 22 | 23 | np.random.seed(123) 24 | 25 | m, n = 1200, 50 26 | noise = np.random.randn(*(m, 1)) 27 | beta1 = np.random.randn(n, 1) 28 | X = np.random.randn(m, n) / np.sqrt(n) 29 | Y = (X @ beta1 + args.noise_lvl * noise).squeeze() 30 | print(X.shape, Y.shape) 31 | 32 | X_train, X_test = ( 33 | X[:1000, :], 34 | X[ 35 | 1000:, 36 | ], 37 | ) 38 | Y_train, Y_test = Y[:1000], Y[1000:] 39 | 40 | ngb = NGBoost( 41 | n_estimators=400, 42 | learning_rate=args.lr, 43 | Dist=Normal, 44 | Base=default_linear_learner, 45 | natural_gradient=args.natural, 46 | minibatch_frac=1.0, 47 | Score=eval(args.score)(), 48 | verbose=True, 49 | verbose_eval=100, 50 | ) 51 | 52 | losses = ngb.fit(X_train, Y_train) 53 | forecast = ngb.pred_dist(X_test) 54 | print("R2:", r2_score(Y_test, forecast.loc)) 55 | -------------------------------------------------------------------------------- /examples/simulations/survival_sim.py: -------------------------------------------------------------------------------- 1 | from argparse import ArgumentParser 2 | 3 | import numpy as np 4 | from matplotlib import pyplot as plt 5 | from sklearn.metrics import r2_score 6 | from sklearn.model_selection import train_test_split 7 | 8 | from ngboost.api import NGBSurvival 9 | from ngboost.distns import Exponential 10 | from ngboost.evaluation import ( 11 | calibration_regression, 12 | calibration_time_to_event, 13 | plot_calibration_curve, 14 | ) 15 | from ngboost.learners import default_linear_learner 16 | from ngboost.scores import MLE 17 | 18 | if __name__ == "__main__": 19 | 20 | argparser = ArgumentParser() 21 | argparser.add_argument("--n-estimators", type=int, default=100) 22 | argparser.add_argument("--lr", type=float, default=1.0) 23 | argparser.add_argument("--eps", type=float, default=1.0) 24 | args = argparser.parse_args() 25 | 26 | m, n = 1000, 5 27 | X = np.random.randn(m, n) / np.sqrt(n) 28 | Y = X @ np.ones((n,)) + 0.5 * np.random.randn(*(m,)) 29 | T = X @ np.ones((n,)) + 0.5 * np.random.randn(*(m,)) + args.eps 30 | E = (T > Y).astype(int) 31 | 32 | print(X.shape, Y.shape, E.shape) 33 | print(f"Event rate: {np.mean(E):.2f}") 34 | 35 | X_tr, X_te, Y_tr, Y_te, T_tr, T_te, E_tr, E_te = train_test_split( 36 | X, Y, T, E, test_size=0.2 37 | ) 38 | 39 | ngb = NGBSurvival( 40 | Dist=Exponential, 41 | n_estimators=args.n_estimators, 42 | learning_rate=args.lr, 43 | natural_gradient=True, 44 | Base=default_linear_learner, 45 | Score=MLE, 46 | verbose=True, 47 | verbose_eval=True, 48 | ) 49 | train_losses = ngb.fit(X_tr, np.exp(np.minimum(Y_tr, T_tr)), E_tr) 50 | 51 | preds = ngb.pred_dist(X_te) 52 | print(f"R2: {r2_score(Y_te, np.log(preds.mean()))}") 53 | 54 | plt.hist(preds.mean(), range=(0, 10), bins=30, alpha=0.5, label="Pred") 55 | plt.hist(np.exp(Y_te), range=(0, 10), bins=30, alpha=0.5, label="True") 56 | plt.legend() 57 | plt.show() 58 | 59 | # since we simulated the data we fully observe all outcomes 60 | # calibration assuming complete observations 61 | pctles, observed, slope, intercept = calibration_regression(preds, Y_te) 62 | plot_calibration_curve(pctles, observed) 63 | plt.show() 64 | 65 | # calibration for partial observations 66 | pctles, observed, slope, intercept = calibration_time_to_event( 67 | preds, np.minimum(Y_te, T_te).squeeze(), E_te.squeeze() 68 | ) 69 | plot_calibration_curve(pctles, observed) 70 | plt.show() 71 | -------------------------------------------------------------------------------- /examples/sklearn_cv.py: -------------------------------------------------------------------------------- 1 | from sklearn.datasets import load_breast_cancer 2 | from sklearn.linear_model import Ridge 3 | from sklearn.model_selection import GridSearchCV, train_test_split 4 | from sklearn.tree import DecisionTreeRegressor 5 | 6 | from ngboost import NGBClassifier 7 | from ngboost.distns import k_categorical 8 | 9 | if __name__ == "__main__": 10 | # An example where the base learner is also searched over (this is how you would vary tree depth): 11 | 12 | X, Y = load_breast_cancer(return_X_y=True) 13 | X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=0.2) 14 | 15 | b1 = DecisionTreeRegressor(criterion="friedman_mse", max_depth=2) 16 | b2 = DecisionTreeRegressor(criterion="friedman_mse", max_depth=4) 17 | b3 = Ridge(alpha=0.0) 18 | 19 | param_grid = { 20 | "n_estimators": [20, 50], 21 | "minibatch_frac": [1.0, 0.5], 22 | "Base": [b1, b2], 23 | } 24 | 25 | ngb = NGBClassifier(natural_gradient=True, verbose=False, Dist=k_categorical(2)) 26 | 27 | grid_search = GridSearchCV(ngb, param_grid=param_grid, cv=5) 28 | grid_search.fit(X_train, Y_train) 29 | print(grid_search.best_params_) 30 | -------------------------------------------------------------------------------- /examples/survival.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import pandas as pd 3 | from sklearn.metrics import mean_squared_error 4 | from sklearn.model_selection import train_test_split 5 | 6 | from ngboost import NGBSurvival 7 | from ngboost.distns import LogNormal 8 | 9 | if __name__ == "__main__": 10 | # Load Boston housing dataset 11 | data_url = "http://lib.stat.cmu.edu/datasets/boston" 12 | raw_df = pd.read_csv(data_url, sep=r"\s+", skiprows=22, header=None) 13 | X = np.hstack([raw_df.values[::2, :], raw_df.values[1::2, :2]]) 14 | Y = raw_df.values[1::2, 2] 15 | 16 | X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=0.2) 17 | 18 | # introduce administrative censoring 19 | T_train = np.minimum(Y_train, 30) 20 | E_train = Y_train > 30 21 | 22 | ngb = NGBSurvival(Dist=LogNormal).fit(X_train, T_train, E_train) 23 | Y_preds = ngb.predict(X_test) 24 | Y_dists = ngb.pred_dist(X_test) 25 | 26 | # test Mean Squared Error 27 | test_MSE = mean_squared_error(Y_preds, Y_test) 28 | print("Test MSE", test_MSE) 29 | 30 | # test Negative Log Likelihood 31 | test_NLL = -Y_dists.logpdf(Y_test.flatten()).mean() 32 | print("Test NLL", test_NLL) 33 | -------------------------------------------------------------------------------- /examples/user-guide/Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | group :jekyll_plugins do 4 | gem 'github-pages' 5 | gem 'jekyll-feed', '~> 0.6' 6 | 7 | # Textbook plugins 8 | gem 'jekyll-redirect-from' 9 | gem 'jekyll-scholar' 10 | end 11 | 12 | # Windows does not include zoneinfo files, so bundle the tzinfo-data gem 13 | gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] 14 | 15 | # Performance-booster for watching directories on Windows 16 | gem 'wdm', '~> 0.1.0' if Gem.win_platform? 17 | 18 | # Development tools 19 | gem 'guard', '~> 2.14.2' 20 | gem 'guard-jekyll-plus', '~> 2.0.2' 21 | gem 'guard-livereload', '~> 2.5.2' 22 | -------------------------------------------------------------------------------- /examples/user-guide/Guardfile: -------------------------------------------------------------------------------- 1 | guard 'jekyll-plus', serve: true do 2 | watch /.*/ 3 | ignore /^_site/ 4 | end 5 | 6 | guard 'livereload' do 7 | watch /.*/ 8 | end 9 | -------------------------------------------------------------------------------- /examples/user-guide/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: help book clean serve 2 | 3 | help: 4 | @echo "Please use 'make ' where is one of:" 5 | @echo " install to install the necessary dependencies for jupyter-book to build" 6 | @echo " book to convert the content/ folder into Jekyll markdown in _build/" 7 | @echo " clean to clean out site build files" 8 | @echo " runall to run all notebooks in-place, capturing outputs with the notebook" 9 | @echo " serve to serve the repository locally with Jekyll" 10 | @echo " build to build the site HTML and store in _build/" 11 | @echo " site to build the site HTML, store in _site/, and serve with Jekyll" 12 | 13 | 14 | install: 15 | jupyter-book install ./ 16 | 17 | book: 18 | jupyter-book build ./ 19 | 20 | runall: 21 | jupyter-book run ./content 22 | 23 | clean: 24 | python scripts/clean.py 25 | 26 | serve: 27 | bundle exec guard 28 | 29 | build: 30 | jupyter-book build ./ --overwrite 31 | 32 | site: build 33 | bundle exec jekyll build 34 | touch _site/.nojekyll 35 | -------------------------------------------------------------------------------- /examples/user-guide/_data/toc.yml: -------------------------------------------------------------------------------- 1 | # This file contains the order and numbering for all sections in the book. 2 | # 3 | # It is a sample TOC file to help you get started. Fill it out with entries 4 | # for your own content. 5 | # 6 | # Each entry has the following schema: 7 | # 8 | # - title: mytitle # Title of chapter or section 9 | # url: /myurl # URL of section relative to the /content/ folder. 10 | # sections: # Contains a list of more entries that make up the chapter's sections 11 | # not_numbered: true # if the section shouldn't have a number in the sidebar 12 | # (e.g. Introduction or appendices) 13 | # expand_sections: true # if you'd like the sections of this chapter to always 14 | # be expanded in the sidebar. 15 | # external: true # Whether the URL is an external link or points to content in the book 16 | # 17 | # Below are some special values that trigger specific behavior: 18 | # - search: true # Will provide a link to a search page 19 | # - divider: true # Will insert a divider in the sidebar 20 | # - header: My Header # Will insert a header with no link in the sidebar 21 | # 22 | # See the links below for an example. 23 | 24 | # Top-level page 25 | - title: User Guide 26 | url: /intro 27 | expand_sections: true 28 | not_numbered: true 29 | sections: 30 | - url: /0-install 31 | - url: /1-useage 32 | - url: /2-tuning 33 | - url: /3-interpretation 34 | - url: /4-saving 35 | - url: /5-dev 36 | 37 | # External link 38 | - title: Package 39 | url: https://github.com/stanfordmlgroup/ngboost 40 | external: true 41 | not_numbered: true 42 | 43 | - title: Paper 44 | url: https://arxiv.org/abs/1910.03225 45 | external: true 46 | not_numbered: true 47 | 48 | - title: Understanding NGBoost 49 | url: https://drive.google.com/file/d/183BWFAdFms81MKy6hSku8qI97OwS_JH_/view?usp=sharing 50 | external: true 51 | not_numbered: true 52 | 53 | # Divider for meta-pages and content page 54 | - divider: true 55 | 56 | # # Add a header and sample content section 57 | # - header: NGBoost Vignette 58 | -------------------------------------------------------------------------------- /examples/user-guide/_includes/buttons.html: -------------------------------------------------------------------------------- 1 |
2 | {% include buttons/download.html %} 3 | {% if page.interact_link %} 4 | {% include buttons/thebelab.html %} 5 | {% include buttons/nbinteract.html %} 6 | {% include buttons/binder.html %} 7 | {% include buttons/jupyterhub.html %} 8 | {% endif %} 9 |
10 | -------------------------------------------------------------------------------- /examples/user-guide/_includes/buttons/binder.html: -------------------------------------------------------------------------------- 1 | {% if site.use_binder_button %} 2 | 3 | {% if site.use_jupyterlab %} 4 | {% assign binder_interact_prefix="urlpath=lab/tree/" %} 5 | {% else %} 6 | {% assign binder_interact_prefix="filepath=" %} 7 | {% endif %} 8 | 9 | {% capture interact_url_binder %}v2/gh/{{ site.binder_repo_org }}/{{ site.binder_repo_name }}/{{ site.binder_repo_branch }}?{{ binder_interact_prefix }}{{ page.interact_link | url_encode }}{% endcapture %} 10 | {% capture interact_icon_binder %}{{ site.images_url | relative_url }}/logo_binder.svg{% endcapture %} 11 | 12 | 13 | 14 | {%- endif %} 15 | -------------------------------------------------------------------------------- /examples/user-guide/_includes/buttons/download.html: -------------------------------------------------------------------------------- 1 | {% if site.use_download_button -%} 2 |
3 | 4 |
5 | {% if page.interact_link -%} 6 | 7 | 8 | 9 | {% endif %} 10 | 11 |
12 |
13 | {%- endif %} 14 | -------------------------------------------------------------------------------- /examples/user-guide/_includes/buttons/jupyterhub.html: -------------------------------------------------------------------------------- 1 | {% if site.use_jupyterhub_button %} 2 | 3 | {% if site.use_jupyterlab %} 4 | {% assign hub_app="lab" %} 5 | {% else %} 6 | {% assign hub_app="notebook" %} 7 | {% endif %} 8 | 9 | {% capture interact_url_jupyterhub %}hub/user-redirect/git-pull?repo={{ site.binder_repo_base }}/{{ site.binder_repo_org }}/{{ site.binder_repo_name }}&branch={{ site.binder_repo_branch }}&subPath={{ page.interact_link | url_encode }}&app={{ hub_app }}{% endcapture %} 10 | {% capture interact_icon_jupyterhub %}{{ site.images_url | relative_url }}/logo_jupyterhub.svg{% endcapture %} 11 | 12 | 13 | {% endif %} 14 | -------------------------------------------------------------------------------- /examples/user-guide/_includes/buttons/nbinteract.html: -------------------------------------------------------------------------------- 1 | {% if site.use_show_widgets_button and page.has_widgets -%} 2 | 3 | {% endif %} 4 | -------------------------------------------------------------------------------- /examples/user-guide/_includes/buttons/thebelab.html: -------------------------------------------------------------------------------- 1 | {% if site.use_thebelab_button -%} 2 | 3 | {% endif %} 4 | -------------------------------------------------------------------------------- /examples/user-guide/_includes/css_entry.scss: -------------------------------------------------------------------------------- 1 | @import 'inuitcss/settings/settings.core'; 2 | @import 'settings/settings.global.scss'; 3 | 4 | @import 'inuitcss/tools/tools.font-size'; 5 | @import 'inuitcss/tools/tools.clearfix'; 6 | @import 'inuitcss/tools/tools.hidden'; 7 | @import 'inuitcss/tools/tools.mq'; 8 | 9 | @import 'inuitcss/elements/elements.page'; 10 | @import 'inuitcss/elements/elements.headings'; 11 | @import 'inuitcss/elements/elements.images'; 12 | @import 'inuitcss/elements/elements.tables'; 13 | @import 'elements/elements.typography'; 14 | @import 'elements/elements.syntax-highlighting'; 15 | @import 'elements/elements.tables'; 16 | @import 'elements/elements.links'; 17 | 18 | @import 'components/components.textbook__page'; 19 | -------------------------------------------------------------------------------- /examples/user-guide/_includes/fb_tags.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /examples/user-guide/_includes/footer.html: -------------------------------------------------------------------------------- 1 |
2 | 3 |
4 | -------------------------------------------------------------------------------- /examples/user-guide/_includes/google_analytics.html: -------------------------------------------------------------------------------- 1 | {% if site.google_analytics.mytrackingcode %} 2 | 3 | 4 | 11 | {% endif %} 12 | -------------------------------------------------------------------------------- /examples/user-guide/_includes/js/nbinteract.html: -------------------------------------------------------------------------------- 1 | {% if site.use_show_widgets_button and page.has_widgets %} 2 | 3 | 4 | 5 | 33 | {% endif %} 34 | -------------------------------------------------------------------------------- /examples/user-guide/_includes/js/print.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 33 | -------------------------------------------------------------------------------- /examples/user-guide/_includes/js/thebelab-cell-button.html: -------------------------------------------------------------------------------- 1 | {% if site.use_thebelab_button -%} 2 | 27 | {% endif %} 28 | -------------------------------------------------------------------------------- /examples/user-guide/_includes/js/thebelab-page-config.html: -------------------------------------------------------------------------------- 1 | 33 | -------------------------------------------------------------------------------- /examples/user-guide/_includes/mathjax.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 29 | 30 | -------------------------------------------------------------------------------- /examples/user-guide/_includes/metadata.json: -------------------------------------------------------------------------------- 1 | { 2 | "@context": "http://schema.org", 3 | "@type": "NewsArticle", 4 | "mainEntityOfPage": "{{ page.url | replace:'index.html','' | prepend: site.baseurl | prepend: site.url }}", 5 | "headline": "{% if page.title %}{{ page.title | escape }}{% else %}{{ site.title | escape }}{% endif %}", 6 | "datePublished": "{% if page.date %}{{ page.date | date_to_xmlschema }}{% else %}{{ site.time | date_to_xmlschema }}{% endif %}", 7 | "dateModified": "{% if page.date %}{{ page.date | date_to_xmlschema }}{% else %}{{ site.time | date_to_xmlschema }}{% endif %}", 8 | "description": "{{ page.content | strip_html | strip_newlines | truncate: 160 }}", 9 | "author": { 10 | "@type": "Person", 11 | "name": "{{ site.author }}" 12 | }, 13 | "publisher": { 14 | "@type": "Organization", 15 | "name": "Data 100 at UC Berkeley", 16 | "logo": { 17 | "@type": "ImageObject", 18 | "url": "{{ site.logo | prepend: site.baseurl | prepend: site.url }}", 19 | "width": 60, 20 | "height": 60 21 | } 22 | }, 23 | "image": { 24 | "@type": "ImageObject", 25 | "url": "{{ site.logo | prepend: site.baseurl | prepend: site.url }}", 26 | "height": 60, 27 | "width": 60 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /examples/user-guide/_includes/page-nav.html: -------------------------------------------------------------------------------- 1 | {% comment %} 2 | Only the URLs from the TOC are used here. The title for 3 | prev/next is pulled from the respective page's metadata. 4 | We loop through the "build" collection to determine the 5 | page title based on the *current* page's next/prev URL. 6 | {% endcomment %} 7 | 38 | -------------------------------------------------------------------------------- /examples/user-guide/_includes/search/lunr/lunr-store.js: -------------------------------------------------------------------------------- 1 | var store = [ 2 | {%- for c in site.collections -%} 3 | {%- if forloop.last -%} 4 | {%- assign l = true -%} 5 | {%- endif -%} 6 | {%- assign docs = c.docs | where_exp:'doc','doc.search != false' -%} 7 | {%- for doc in docs -%} 8 | {%- if doc.header.teaser -%} 9 | {%- capture teaser -%}{{ doc.header.teaser }}{%- endcapture -%} 10 | {%- else -%} 11 | {%- assign teaser = site.teaser -%} 12 | {%- endif -%} 13 | { 14 | "title": {{ doc.title | jsonify }}, 15 | {% assign truncateWords=site.search_max_words_in_content %} 16 | "excerpt": {{ doc.search | jsonify }}, 17 | "categories": {{ doc.categories | jsonify }}, 18 | "tags": {{ doc.tags | jsonify }}, 19 | "url": {{ doc.url | absolute_url | jsonify }}, 20 | "teaser": 21 | {%- if teaser contains "://" -%} 22 | {{ teaser | jsonify }} 23 | {%- else -%} 24 | {{ teaser | absolute_url | jsonify }} 25 | {%- endif -%} 26 | }{%- unless forloop.last and l -%},{%- endunless -%} 27 | {%- endfor -%} 28 | {%- endfor -%}] 29 | -------------------------------------------------------------------------------- /examples/user-guide/_includes/topbar.html: -------------------------------------------------------------------------------- 1 |
2 | 3 |
4 | 12 | {% include buttons.html %} 13 |
14 | 15 | 20 | 21 | Search 22 | 23 |
24 | -------------------------------------------------------------------------------- /examples/user-guide/_layouts/default.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | {% include head.html %} 4 | 5 | 6 | {% include js/thebelab-page-config.html %} 7 | 8 | 9 |
10 | {% include sidebar.html %} 11 | {% if page.search_page != true %} 12 | {% endif %} 13 | {% include topbar.html %} 14 |
15 |
16 | {{ content }} 17 |
18 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /examples/user-guide/_sass/components/_components.book__topbar.scss: -------------------------------------------------------------------------------- 1 | .c-topbar__label { 2 | @include inuit-font-size(12px); 3 | display: inline-block; 4 | margin-left: $spacing-unit-tiny; 5 | vertical-align: middle; 6 | text-transform: uppercase; 7 | } 8 | 9 | .c-topbar { 10 | .hamburger, .buttons { 11 | float: left; 12 | } 13 | 14 | #js-sidebar-toggle { 15 | margin-right: 5px; 16 | padding-top: 4px; 17 | } 18 | 19 | span.hamburger-box { 20 | width: 40px; 21 | height: 30px; 22 | padding-left: 10px; 23 | } 24 | 25 | .c-topbar__buttons { 26 | @include mq($from: tablet) { 27 | width: calc(100% - #{$right-sidebar-width} - 20px) 28 | } 29 | } 30 | 31 | .topbar-right-button { 32 | display: block; 33 | float: right; 34 | padding: 0 1rem; 35 | 36 | img { 37 | width: 20px; 38 | margin-top: 4px; 39 | } 40 | } 41 | } 42 | 43 | // Download buttons 44 | 45 | .download-buttons { 46 | display: none; 47 | position: absolute; 48 | 49 | button { 50 | min-width: 100px !important; 51 | border: 1px white solid !important; 52 | border-radius: 0 !important; 53 | } 54 | } 55 | 56 | .download-buttons-dropdown { 57 | position: relative; 58 | display: inline-block; 59 | 60 | &:hover div.download-buttons { 61 | display: block; 62 | } 63 | 64 | img { 65 | height: 18px; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /examples/user-guide/_sass/components/_components.interact-button.scss: -------------------------------------------------------------------------------- 1 | /** 2 | * Stylings for Interact and Show Widget buttons. 3 | * 4 | * [1]: We abuse CSS selector specificity here since the buttons at the top of 5 | * the notebook might have both .interact-button and .js=nbinteract-widget. 6 | * [2]: We want the top buttons to be large. 7 | * [3]: However, a .js=nbinteract-widget appearing alone midway through the 8 | * notebook should be small. 9 | * 10 | */ 11 | 12 | $color-interact-button: #5a5a5a !default; 13 | 14 | %interact-button { 15 | @include inuit-font-size(14px); 16 | background-color: $color-interact-button; 17 | border-radius: 3px; 18 | border: none; 19 | color: white; 20 | cursor: pointer; 21 | display: inline-block; 22 | font-weight: 700; 23 | /* [2] */ 24 | padding: $spacing-unit-tiny $spacing-unit-med; 25 | text-decoration: none; 26 | 27 | &:hover, 28 | &:focus { 29 | text-decoration: none; 30 | } 31 | } 32 | 33 | .interact-button-logo { 34 | height: 1.35em; 35 | padding-right: 10px; 36 | margin-left: -5px; 37 | } 38 | 39 | .buttons { 40 | margin-bottom: $spacing-unit; 41 | 42 | /* [1] */ 43 | .interact-button { 44 | @extend %interact-button; 45 | } 46 | } 47 | 48 | .js-nbinteract-widget { 49 | @extend %interact-button; 50 | 51 | /* [3] */ 52 | padding: $spacing-unit-tiny $spacing-unit; 53 | margin-bottom: $spacing-unit-small; 54 | } 55 | 56 | // If the interact button link is changed with a REST param 57 | div.interact-context { 58 | display: inline; 59 | padding-left: 1em; 60 | } 61 | -------------------------------------------------------------------------------- /examples/user-guide/_sass/components/_components.page__footer.scss: -------------------------------------------------------------------------------- 1 | .footer { 2 | text-align: center; 3 | font-size: 14px; 4 | padding: 20px; 5 | opacity: 0.7; 6 | margin-bottom: 0px; 7 | } 8 | -------------------------------------------------------------------------------- /examples/user-guide/_sass/components/_components.page__nav.scss: -------------------------------------------------------------------------------- 1 | /** 2 | * Styling for the Next Page / Previous Page links at the bottom of textbook 3 | * pages. 4 | */ 5 | 6 | $color-nav-links: rgba(0, 140, 255, 0.7); 7 | 8 | .c-page__nav__prev, 9 | .c-page__nav__next { 10 | flex: 1; 11 | color: $color-nav-links; 12 | border: 1px solid $color-nav-links; 13 | border-radius: 3px; 14 | padding: $spacing-unit-small 0; 15 | } 16 | 17 | .c-page__nav__next { 18 | text-align: right; 19 | } 20 | -------------------------------------------------------------------------------- /examples/user-guide/_sass/components/_components.page__onthispage.scss: -------------------------------------------------------------------------------- 1 | /** 2 | * Styling for the onthispage elements. 3 | * 4 | * [1]: The sidebar is implemented as ul and li elements so we need to remove 5 | * the bullets and margins. Also make chapter fonts a bit bigger. 6 | * [2]: The entries are tags so we need to remove the default styling. 7 | * [3]: The sidebar divider is just an empty element with a border. 8 | * [4]: The current section needs a higher specificity to override the :hover 9 | * selectors used previously. 10 | * [5]: The logo displayed above the sidebar 11 | * [6]: The footer at the bottom of the sidebar 12 | */ 13 | $color-sidebar-bg: rgba(255, 255, 255, 0) !default; 14 | $color-sidebar-entry: #364149 !default; 15 | $color-sidebar-entry--active: $color-links !default; 16 | $color-sidebar-divider: #bbb !default; 17 | 18 | .c-textbook__sidebar { 19 | background-color: $color-sidebar-bg; 20 | padding: $spacing-unit-small; 21 | 22 | @include inuit-font-size(14px); 23 | border-right: 1px solid rgba(0, 0, 0, 0.07); 24 | opacity: 0.6; 25 | -webkit-transition: opacity 0.2s ease-in-out; 26 | transition: opacity 0.2s ease-in-out; 27 | 28 | &:hover { 29 | opacity: 1; 30 | } 31 | } 32 | 33 | /* [1] */ 34 | .c-sidebar__chapters { 35 | list-style: none; 36 | margin-left: 0; 37 | margin-bottom: 0; 38 | } 39 | 40 | li.c-sidebar__chapter > a { 41 | font-size: 1.2em; 42 | } 43 | 44 | /* [1] */ 45 | .c-sidebar__sections, .c-sidebar__subsections { 46 | list-style: none; 47 | margin-bottom: 0; 48 | } 49 | 50 | .c-sidebar__sections { 51 | margin-left: $spacing-unit-small; 52 | } 53 | 54 | .c-sidebar__subsections { 55 | margin-left: 20px; 56 | } 57 | 58 | /* [2] */ 59 | .c-sidebar__entry { 60 | display: block; 61 | 62 | padding: $spacing-unit-tiny; 63 | 64 | color: $color-sidebar-entry; 65 | text-decoration: none; 66 | 67 | &:hover { 68 | text-decoration: underline; 69 | } 70 | 71 | &:visited { 72 | color: $color-sidebar-entry; 73 | } 74 | } 75 | 76 | /* [4] */ 77 | .c-sidebar__entry--active.c-sidebar__entry--active { 78 | color: $color-sidebar-entry--active; 79 | } 80 | 81 | /* [3] */ 82 | .c-sidebar__divider { 83 | border-top: 1px solid $color-sidebar-divider; 84 | margin: $spacing-unit-tiny; 85 | } 86 | 87 | /* [5] */ 88 | img.textbook_logo { 89 | margin-top: 20px; 90 | max-height: 100px; 91 | margin: 0px auto 20px auto; 92 | display: block; 93 | } 94 | 95 | /* [6] */ 96 | p.sidebar_footer { 97 | text-align: center; 98 | padding: 10px 20px 0px 0px; 99 | font-size: .9em; 100 | } 101 | -------------------------------------------------------------------------------- /examples/user-guide/_sass/components/_components.search.scss: -------------------------------------------------------------------------------- 1 | /* ========================================================================== 2 | SEARCH 3 | ========================================================================== */ 4 | // Taken from https://github.com/mmistakes/minimal-mistakes 5 | // Variables 6 | $large: 1024px !default; 7 | $x-large: 1280px !default; 8 | $type-size-1: 2.441em !default; 9 | $type-size-2: 1.953em !default; 10 | $type-size-3: 1.563em !default; 11 | $type-size-6: 0.75em !default; 12 | $intro-transition: intro 0.3s both !default; 13 | 14 | // Rules 15 | .layout--search { 16 | .archive__item-teaser { 17 | margin-bottom: 0.25em; 18 | } 19 | } 20 | 21 | .search__toggle { 22 | margin-left: 1rem; 23 | margin-right: 1rem; 24 | border: 0; 25 | outline: none; 26 | color: #393e46; 27 | background-color: transparent; 28 | cursor: pointer; 29 | -webkit-transition: 0.2s; 30 | transition: 0.2s; 31 | 32 | &:hover { 33 | color: #000; 34 | } 35 | } 36 | 37 | .search-icon { 38 | width: 100%; 39 | height: 100%; 40 | } 41 | 42 | .search-content { 43 | //display: none; 44 | //visibility: hidden; 45 | padding-top: 1em; 46 | padding-bottom: 1em; 47 | 48 | &__inner-wrap { 49 | width: 100%; 50 | margin-left: auto; 51 | margin-right: auto; 52 | padding-left: 1em; 53 | padding-right: 1em; 54 | -webkit-animation: $intro-transition; 55 | animation: $intro-transition; 56 | -webkit-animation-delay: 0.15s; 57 | animation-delay: 0.15s; 58 | 59 | .search-input { 60 | display: block; 61 | margin-bottom: 0; 62 | padding: 0; 63 | border: none; 64 | outline: none; 65 | box-shadow: none; 66 | background-color: transparent; 67 | font-size: $type-size-3; 68 | } 69 | } 70 | 71 | &.is--visible { 72 | display: block; 73 | visibility: visible; 74 | 75 | &::after { 76 | content: ""; 77 | display: block; 78 | } 79 | } 80 | 81 | .results__found { 82 | margin-top: 0.5em; 83 | font-size: $type-size-6; 84 | } 85 | 86 | .archive__item { 87 | margin-bottom: 2em; 88 | } 89 | 90 | .archive__item-title { 91 | margin-top: 0; 92 | } 93 | 94 | .archive__item-excerpt { 95 | margin-bottom: 0; 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /examples/user-guide/_sass/components/_components.thebelab.scss: -------------------------------------------------------------------------------- 1 | 2 | .thebelab-cell { 3 | // To ensure that thebelab cells are always the top of the Z-stack 4 | position: relative; 5 | z-index: 999; 6 | } 7 | 8 | .thebelab-button { 9 | z-index: 999; 10 | display: inline-block; 11 | padding: 0.35em 1.2em; 12 | margin: 0px 1px; 13 | border-radius: 0.12em; 14 | box-sizing: border-box; 15 | text-decoration: none; 16 | font-family: 'Roboto', sans-serif; 17 | font-weight: 300; 18 | text-align: center; 19 | transition: all 0.2s; 20 | background-color: #dddddd; 21 | border: 0.05em solid white; 22 | color: #000000; 23 | } 24 | 25 | .thebelab-button:hover{ 26 | border: 0.05em solid black; 27 | background-color: #fcfcfc; 28 | } 29 | 30 | 31 | div.jp-OutputArea-output { 32 | padding: 5px; 33 | } 34 | -------------------------------------------------------------------------------- /examples/user-guide/_sass/hamburgers/_base.scss: -------------------------------------------------------------------------------- 1 | // Hamburger 2 | // ================================================== 3 | .hamburger { 4 | padding: $hamburger-padding-y $hamburger-padding-x; 5 | display: inline-block; 6 | cursor: pointer; 7 | 8 | transition-property: opacity, filter; 9 | transition-duration: $hamburger-hover-transition-duration; 10 | transition-timing-function: $hamburger-hover-transition-timing-function; 11 | 12 | // Normalize (