Giter VIP home page Giter VIP logo

kulprit's Introduction

Kullback-Leibler projections for Bayesian model selection in Python.

PyPi version Build Status codecov Code style: black

Overview

Kulprit (Pronounced: kuːl.prɪt) is a package for variable selection for Bambi models. Kulprit is under active development so use it with care. If you find any bugs or have any feature requests, please open an issue.

Installation

Kulprit requires a working Python interpreter (3.9+). We recommend installing Python and key numerical libraries using the Anaconda Distribution, which has one-click installers available on all major platforms.

Assuming a standard Python environment is installed on your machine (including pip), Kulprit itself can be installed in one line using pip:

pip install kulprit

Alternatively, if you want the bleeding edge version of the package you can install it from GitHub:

pip install git+https://github.com/bambinos/kulprit.git

Documentation

The Kulprit documentation can be found in the official docs. If you are not familiar with the theory behind Kulprit or need some practical advice on how to use Kulprit or interpret its results, we recommend you read the paper Robust and efficient projection predictive inference. You may also find useful this guide on Cross-Validation and model selection.

Development

Read our development guide in CONTRIBUTING.md.

Contributions

Kulprit is a community project and welcomes contributions. Additional information can be found in the Contributing Readme.

For a list of contributors see the GitHub contributor page

Citation

If you use Bambi and want to cite it please use

@misc{mclatchie2023,
    title={Robust and efficient projection predictive inference}, 
    author={Yann McLatchie and Sölvi Rögnvaldsson and Frank Weber and Aki Vehtari},
    year={2023},
    eprint={2306.15581},
    archivePrefix={arXiv},
    primaryClass={stat.ME}
}

Donations

If you want to support Kulprit financially, you can make a donation to our sister project PyMC.

Code of Conduct

Kulprit wishes to maintain a positive community. Additional details can be found in the Code of Conduct

License

MIT License

kulprit's People

Contributors

aloctavodia avatar nsiccha avatar tomicapretto avatar yannmclatchie avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

kulprit's Issues

Add tutorials

Add two tutorials to the docs:

  1. a general kulprit workflow (similar to the main projpred vignette);
  2. an implementation of a discrete observational family using both Poisson and Binomial families.

Accommodate more families

Currently only the Gaussian observation family is implemented in kulprit. We should also allow the use Binomial and Poisson observation families in the reference model.

Replace PyTorch with Aesara

I don't thing this is a priority at the moment. But at some point in the future, making this change will be beneficial. The two most obvious benefits will be removing one dependency, as aesara is already a Bambi dependency. And avoid duplicating code from bambi.

We could use this issue to track the functions that we actually need tom PyTorch that are currently absent from aesara. And then decided if those should be added upstream or we can add it as part of kulprit. I think we just require a couple of functions or so.

Need an intercept term for Projection Predictive Inference?

Hi all,

I'm trying to write a course using the Bayesian Analysis with Python book, and I'm reusing a lot of those examples.
But I've run into trouble with kulprit, and I'm hoping I can get some help.

When I run: ppi = kpt.ProjectionPredictive(model_body,idata_body) in Google Colab, I get the following error:


AttributeError Traceback (most recent call last)
in <cell line: 1>()
----> 1 ppi = kpt.ProjectionPredictive(model_body,idata_body)

/usr/local/lib/python3.10/dist-packages/kulprit/reference.py in init(self, model, idata)
40 """
41 # test that the reference model has an intercept term
---> 42 if model.response_component.intercept_term is None:
43 raise UserWarning(
44 "The procedure currently requires reference models to have an intercept term."

AttributeError: 'ResponseComponent' object has no attribute 'intercept_term'


The full notebook I'm using is here: https://github.com/thedarredondo/data-science-fundamentals/blob/main/Unit6/Unit6NotesAK.ipynb

The relevant code for the issue, as far as I can tell, is:

!pip install git+https://github.com/bambinos/kulprit.git
!pip install git+https://github.com/bambinos/bambi.git
import kulprit as kpt
import bambi as bmb
import pandas as pd

body = pd.read_csv('https://raw.githubusercontent.com/thedarredondo/data-science-fundamentals/main/Data/body_fat.csv')

model_body = bmb.Model("siri ~ age + weight + height + abdomen + thigh + wrist", data=body)
idata_body = model_body.fit(idata_kwargs={'log_likelihood': True})

ppi = kpt.ProjectionPredictive(model_body,idata_body)

UserWarning: Incompatible model and inference data.

Hi,
Beginner here. I tried to reduce my model to as few variables as possible, and follow the Quickstart, but still getting this error. Not sure how to debug.

ppi = kpt.ProjectionPredictive(model, idata)

Repro is here: https://github.com/lucabol/divs/blob/master/Analysis.ipynb

Full error below

UserWarning                               Traceback (most recent call last)
Cell In[6], [line 3](vscode-notebook-cell:?execution_count=6&line=3)
      [1](vscode-notebook-cell:?execution_count=6&line=1) #idata.to_netcdf("kptidata1.nc")
      [2](vscode-notebook-cell:?execution_count=6&line=2) #idata = az.from_netcdf("kptidata1.nc")
----> [3](vscode-notebook-cell:?execution_count=6&line=3) ppi = kpt.ProjectionPredictive(model, idata)
      [4](vscode-notebook-cell:?execution_count=6&line=4) ppi.search()

File ~/miniconda3/envs/bap3/lib/python3.11/site-packages/kulprit/reference.py:62, in ProjectionPredictive.__init__(self, model, idata)
     [60](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/home/lucabol/dev/divs/~/miniconda3/envs/bap3/lib/python3.11/site-packages/kulprit/reference.py:60) # test compatibility between model and idata
     [61](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/home/lucabol/dev/divs/~/miniconda3/envs/bap3/lib/python3.11/site-packages/kulprit/reference.py:61) if not check_model_idata_compatability(model=model, idata=idata):
---> [62](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/home/lucabol/dev/divs/~/miniconda3/envs/bap3/lib/python3.11/site-packages/kulprit/reference.py:62)     raise UserWarning("Incompatible model and inference data.")
     [64](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/home/lucabol/dev/divs/~/miniconda3/envs/bap3/lib/python3.11/site-packages/kulprit/reference.py:64) # log reference model and inference data
     [65](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/home/lucabol/dev/divs/~/miniconda3/envs/bap3/lib/python3.11/site-packages/kulprit/reference.py:65) self.model = model

UserWarning: Incompatible model and inference data.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.