{"id":13569500,"url":"https://github.com/lmc2179/bayesian_bootstrap","last_synced_at":"2026-04-09T00:02:28.942Z","repository":{"id":20276122,"uuid":"89321721","full_name":"lmc2179/bayesian_bootstrap","owner":"lmc2179","description":"bayesian bootstrapping in python","archived":false,"fork":false,"pushed_at":"2022-03-12T15:58:35.000Z","size":185,"stargazers_count":123,"open_issues_count":7,"forks_count":18,"subscribers_count":6,"default_branch":"master","last_synced_at":"2026-01-03T02:05:59.155Z","etag":null,"topics":["bayesian-inference","bootstrap","bootstrap-resampling","posterior-distributions","posterior-samples","python"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lmc2179.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-04-25T05:42:32.000Z","updated_at":"2025-11-05T17:28:01.000Z","dependencies_parsed_at":"2022-09-13T22:00:32.644Z","dependency_job_id":null,"html_url":"https://github.com/lmc2179/bayesian_bootstrap","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/lmc2179/bayesian_bootstrap","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lmc2179%2Fbayesian_bootstrap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lmc2179%2Fbayesian_bootstrap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lmc2179%2Fbayesian_bootstrap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lmc2179%2Fbayesian_bootstrap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lmc2179","download_url":"https://codeload.github.com/lmc2179/bayesian_bootstrap/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lmc2179%2Fbayesian_bootstrap/sbom","scorecard":{"id":596064,"data":{"date":"2025-08-11","repo":{"name":"github.com/lmc2179/bayesian_bootstrap","commit":"93b8cf41b0675ec24a18e554f5011cdd07de7d91"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3.8,"checks":[{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Code-Review","score":6,"reason":"Found 7/11 approved changesets -- score normalized to 6","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/python-publish.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Pinned-Dependencies","score":2,"reason":"dependency not pinned by hash detected -- score normalized to 2","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/python-publish.yml:21: update your workflow using https://app.stepsecurity.io/secureworkflow/lmc2179/bayesian_bootstrap/python-publish.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/python-publish.yml:23: update your workflow using https://app.stepsecurity.io/secureworkflow/lmc2179/bayesian_bootstrap/python-publish.yml/master?enable=pin","Warn: pipCommand not pinned by hash: .github/workflows/python-publish.yml:28","Warn: pipCommand not pinned by hash: .github/workflows/python-publish.yml:29","Info:   0 out of   2 GitHub-owned GitHubAction dependencies pinned","Info:   1 out of   1 third-party GitHubAction dependencies pinned","Info:   0 out of   2 pipCommand dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Vulnerabilities","score":6,"reason":"4 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: PYSEC-2024-110 / GHSA-jw8x-6495-233v","Warn: Project is vulnerable to: PYSEC-2023-102","Warn: Project is vulnerable to: PYSEC-2023-114","Warn: Project is vulnerable to: GHSA-g7vv-2v7x-gj9p"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 26 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-20T23:10:25.267Z","repository_id":20276122,"created_at":"2025-08-20T23:10:25.268Z","updated_at":"2025-08-20T23:10:25.268Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31579058,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-08T14:31:17.711Z","status":"ssl_error","status_checked_at":"2026-04-08T14:31:17.202Z","response_time":54,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bayesian-inference","bootstrap","bootstrap-resampling","posterior-distributions","posterior-samples","python"],"created_at":"2024-08-01T14:00:40.773Z","updated_at":"2026-04-09T00:02:28.917Z","avatar_url":"https://github.com/lmc2179.png","language":"Python","funding_links":[],"categories":["Uncategorized"],"sub_categories":["Uncategorized"],"readme":"# `bayesian_bootstrap` ![test badge](https://travis-ci.org/lmc2179/bayesian_bootstrap.svg?branch=master) [![PyPI version](https://badge.fury.io/py/bayesian_bootstrap.svg)](https://badge.fury.io/py/bayesian_bootstrap)\n\n`bayesian_bootstrap` is a package for Bayesian bootstrapping in Python. For an overview of the Bayesian bootstrap, I highly recommend reading [Rasmus Bååth's writeup](http://www.sumsar.net/blog/2015/04/the-non-parametric-bootstrap-as-a-bayesian-model/).  This Python package is similar to his [R package](http://www.sumsar.net/blog/2016/02/bayesboot-an-r-package/). \n\nThis README contains some examples, below. For the documentation of the package's API, see the [docs](http://htmlpreview.github.io/?https://github.com/lmc2179/bayesian_bootstrap/blob/master/docs/bootstrap_documentation.html).\n\nThis package is on pypi - you can install it with `pip install bayesian_bootstrap`.\n\n# Overview of the `bayesian_bootstrap` module\n\nThis module contains tools for doing approximate bayesian inference using the Bayesian Bootstrap introduced in [Rubin's _The Bayesian Bootstrap_](https://projecteuclid.org/euclid.aos/1176345338).\n\nIt contains the following:\n\n* The `mean` and `var` functions, which simulate the posterior distributions of the mean and variance\n\n* The `bayesian_bootstrap` function, which simulates the posterior distribution of an arbitrary statistic\n\n* The `BayesianBootstrapBagging` class, a wrapper allowing users to generate ensembles of regressors/classifiers\nusing Bayesian Bootstrap resampling. A base class with a scikit-learn like estimator needs to be provided. See also \nthe `bayesian_bootstrap_regression` function.\n\n* The `central_credible_interval` and `highest_density_interval` functions, which compute credible intervals from\nposterior samples.\n\nFor more information about the function signatures above, see the examples below or the docstrings of each function/class.\n\nOne thing that's worth making clear is the interpretation of the parameters of the `bayesian_bootstrap`, `BayesianBootstrapBagging`, and `bayesian_bootstrap_regression` functions, which all do sampling within each bootstrap replication:\n\n* The number of replications is the number of times the statistic of interested will be replicated. If we think about the classical bootstrap, this is the number of times your dataset is resampled. If we think about it from a bayesian point of view, this is the number of draws from the posterior distribution.\n\n* The resample size is the size of the dataset used to calculate the statistic of interest in each replication. More is better - you'll probably want this to be at least as large as your original dataset.\n\n# Example: Estimating the mean\nLet's say that we observe some data points, and we wish to simulate the posterior distribution of their mean.\n\nThe following code draws four data points from an exponential distribution:\n```\nX = np.random.exponential(7, 4)\n```\nNow, we are going to simulate draws from the posterior of the mean. `bayesian_bootstrap` includes a `mean` function in \nthe `bootstrap` module that will do this for you.\n\nThe code below performs the simulation and calculates the 95% highest density interval using 10,000 bootstrap replications. It also uses the wonderful \n`seaborn` library to visualize the histogram with a Kernel density estimate. \n\nIncluded for reference in the image is the same dataset used in a classical bootstrap, to illustrate the comparative \nsmoothness of the bayesian version.\n```\nfrom bayesian_bootstrap import mean, highest_density_interval\nposterior_samples = mean(X, 10000)\nl, r = highest_density_interval(posterior_samples)\n\nplt.title('Bayesian Bootstrap of mean')\nsns.distplot(posterior_samples, label='Bayesian Bootstrap Samples')\nplt.plot([l, r], [0, 0], linewidth=5.0, marker='o', label='95% HDI')\n```\n\nThe above code uses the `mean` method to simulate the posterior distribution of the mean. However, it is a special \n(if very common) case, along with `var` - all other statistics should use the `bayesian_bootstrap` method. The\n following code demonstrates doing this for the posterior of the mean:\n\n```\nfrom bayesian_bootstrap import bayesian_bootstrap\nposterior_samples = bayesian_bootstrap(X, np.mean, 10000, 100)\n```\n\n![Posterior](bayesian_bootstrap/demos/readme_exponential.png)\n\n# Example: Regression modelling\n\u003c!--\nProblem setup\n\nSample data points\n\nShow scatterplot + code\n\nShow posterior samples for slope\n\nShow show scatterplot with prediction bands\n--\u003e\nLet's take another example - fitting a linear regression model. The following code samples a few points in the plane.\nThe mean is y = x, and normally distributed noise is added.\n```\nX = np.random.normal(0, 1, 5).reshape(-1, 1)\ny = X.reshape(1, -1).reshape(5) + np.random.normal(0, 1, 5)\n```\nWe build models via bootstrap resampling, creating an ensemble of models via bootstrap aggregating. A \n`BayesianBootstrapBagging` wrapper class is available in the library, which is a bayesian analogue to scikit-learn's \n`BaggingRegressor` and `BaggingClassifer` classes.\n```\nm = BayesianBootstrapBagging(LinearRegression(), 10000, 1000)\nm.fit(X, y)\n```\nOnce we've got our ensemble trained, we can make interval predictions for new inputs by calculating their HDIs under the\nensemble:\n```\nX_plot = np.linspace(min(X), max(X))\ny_predicted = m.predict(X_plot.reshape(-1, 1))\ny_predicted_interval = m.predict_highest_density_interval(X_plot.reshape(-1, 1), 0.05)\n\nplt.scatter(X.reshape(1, -1), y)\nplt.plot(X_plot, y_predicted, label='Mean')\nplt.plot(X_plot, y_predicted_interval[:,0], label='95% HDI Lower bound')\nplt.plot(X_plot, y_predicted_interval[:,1], label='95% HDI Upper bound')\nplt.legend()\nplt.savefig('readme_regression.png', bbox_inches='tight')\n```\n![Posterior](bayesian_bootstrap/demos/readme_regression.png)\n\nUsers interested in accessing the base models can do so via the `base_models_` attribute of the object.\n\n# Contributions\n\nInterested in contributing? We'd love to have your help! Please keep the following in mind:\n\n* Bug fixes are welcome! Make sure you reference the issue number that is being resolved, and that all test cases in `tests` pass.\n\n* New features are welcome as well! Any new features should include docstrings and unit tests in the `tests` directory.\n\n* If you want to contribute a case study or other documentation, feel free to write up a github-flavored markdown document or ipython notebook and put it in the `examples` folder before issuing a pull request.\n\nCredit for past contributions:\n\n* [roya0045](https://github.com/roya0045) implemented the original version of the low-memory optimizations.\n* [JulianWgs](https://github.com/JulianWgs) implemented the Bayesian machine learning model using weight distributions instead of resampling and a weighted Pearson correlation coefficient. He also refactored the weighted mean and covariance function to accept weight matrices.\n* [genos](https://github.com/genos) simplified importing and updated the RNG usage to the current numpy standard.\n\n# Further reading\n\n* [_The Bayesian Bootstrap_, Rubin, 1981](https://projecteuclid.org/euclid.aos/1176345338)\n\n* [Rasmus Bååth's original writeup on the Bayesian Bootstrap](http://www.sumsar.net/blog/2015/04/the-non-parametric-bootstrap-as-a-bayesian-model/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flmc2179%2Fbayesian_bootstrap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flmc2179%2Fbayesian_bootstrap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flmc2179%2Fbayesian_bootstrap/lists"}