ProbFlow is a Python package for building probabilistic Bayesian models with TensorFlow Probability, performing variational inference with those models, and evaluating the models’ inferences. It provides both high-level Layers for building Bayesian neural networks, and low-level modules for constructing custom Bayesian models.
It’s very much still a work in progress.
- Git repository: http://github.com/brendanhasz/probflow
- Documentation: http://probflow.readthedocs.io
- Bug reports: http://github.com/brendanhasz/probflow/issues
With ProbFlow, the core building blocks of a Bayesian model are parameters, layers, and probability distributions (and, of course, the input data). Layers define how parameters interact with the independent variables (the features) to predict the probability distribution of the dependent variables (the target).
For example, a simple Bayesian linear regression
can be built with ProbFlow by:
from probflow import Input, Parameter, ScaleParameter, Normal feature = Input() weight = Parameter() bias = Parameter() noise_std = ScaleParameter() predictions = weight*feature + bias model = Normal(predictions, noise_std)
Then, the model can be fit using 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)
Compute probabilistic predictions for new data, with 95% confidence intervals:
Evaluate your model’s performance using various metrics:
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:
and diagnose where your model is having problems capturing uncertainty:
ProbFlow also provides more complex layers, such as those required for building Bayesian neural networks. A multi-layer Bayesian neural network can be built and fit using ProbFlow in only a few lines:
from probflow import Sequential, Dense, ScaleParameter, Normal predictions = Sequential(layers=[ Dense(units=128, activation='relu'), Dense(units=64, activation='relu'), Dense(units=1) ]) noise_std = ScaleParameter() model = Normal(predictions, noise_std) model.fit(x, y)
For convenience, ProbFlow also includes several ready-made 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
from probflow import LinearRegression model = LinearRegression() model.fit(x, y)
And the multi-layer Bayesian neural net could have been made more easily by using ProbFlow’s ready-made
from probflow import DenseRegression model = DenseRegression(units=[128, 64, 1]) model.fit(x, y)
Using parameters, layers, and distributions as simple building blocks, ProbFlow allows for the painless creation of more complicated Bayesian models like generalized linear models, neural matrix factorization models, and mixed effects models. Take a look at the Examples section and the User Guide for more!
Then, you can use pip to install ProbFlow itself from the GitHub source:
pip install git+http://github.com/brendanhasz/probflow.git
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 layers and distributions.
Why the name, ProbFlow?¶
Because it’s a package for probabilistic modeling, and it’s built on TensorFlow. ¯\_(ツ)_/¯