ProbFlow is a Python package for building probabilistic Bayesian models with TensorFlow or PyTorch, performing stochastic variational inference with those models, and evaluating the models’ inferences. It provides both high-level Modules for building Bayesian neural networks, as well as low-level Parameters and Distributions for constructing custom Bayesian models.
It’s very much still a work in progress.
Git repository: http://github.com/brendanhasz/probflow
Bug reports: http://github.com/brendanhasz/probflow/issues
ProbFlow allows you to quickly and
painlessly less painfully build, fit, and evaluate custom Bayesian models (or ready-made ones!) which run on top of either TensorFlow and TensorFlow Probability or PyTorch.
With ProbFlow, the core building blocks of a Bayesian model are parameters and probability distributions (and, of course, the input data). Parameters define how the independent variables (the features) predict the probability distribution of the dependent variables (the target).
For example, a simple Bayesian linear regression
can be built by creating a ProbFlow Model:
Then, the model can be fit using stochastic variational inference, in one line:
# x and y are Numpy arrays or pandas DataFrame/Series model.fit(x, y)
You can generate predictions for new data:
# x_test is a Numpy array or pandas DataFrame >>> model.predict(x_test) [0.983]
Compute probabilistic predictions for new data, with 95% confidence intervals:
Evaluate your model’s performance using various metrics:
>>> model.metric('mse', x_test, y_test) 0.217
Inspect the posterior distributions of your fit model’s parameters, with 95% confidence intervals:
Investigate how well your model is capturing uncertainty by examining how accurate its predictive intervals are:
>>> model.pred_dist_coverage(ci=0.95) 0.903
and diagnose where your model is having problems capturing uncertainty:
ProbFlow also provides more complex modules, such as those required for building Bayesian neural networks. Also, you can mix ProbFlow with TensorFlow (or PyTorch!) code. For example, even a somewhat complex multi-layer Bayesian neural network like this:
Can be built and fit with ProbFlow in only a few lines:
For convenience, ProbFlow also includes several pre-built models for standard tasks (such as linear regressions, logistic regressions, and multi-layer dense neural networks). For example, the above linear regression example could have been done with much less work by using ProbFlow’s ready-made
model = pf.LinearRegression(x.shape) model.fit(x, y)
And a multi-layer Bayesian neural net can be made easily using ProbFlow’s ready-made
model = pf.DenseRegression([x.shape, 128, 64, 1]) model.fit(x, y)
Using parameters and distributions as simple building blocks, ProbFlow allows for the painless creation of more complicated Bayesian models like generalized linear models, deep time-to-event models, neural matrix factorization models, and Gaussian mixture models. Take a look at the Examples and the User Guide for more!
Then, you can install ProbFlow itself:
pip install probflow
Pull requests are totally welcome! Any contribution would be appreciated, from things as minor as pointing out typos to things as major as writing new applications and distributions.
Why the name, ProbFlow?¶
Because it’s a package for probabilistic modeling, and it was built on TensorFlow. ¯\_(ツ)_/¯