pymc-learn: Practical probabilistic machine learning in Python





GitHub Stars



Last Commit

2yrs ago







Copyright (c) 2019 Pymc-learn Developers



pymc-learn: Practical Probabilistic Machine Learning in Python

.. image:: :width: 350px :alt: Pymc-Learn logo :align: center

|status| |Travis| |Coverage| |Docs| |License| |Pypi| |Binder|


#. `Github repo`_
#. `What is pymc-learn?`_
#. `Quick Install`_
#. `Quick Start`_
#. `Index`_

.. _Github repo:

What is pymc-learn?

pymc-learn is a library for practical probabilistic machine learning in Python.

It provides a variety of state-of-the art probabilistic models for supervised and unsupervised machine learning. It is inspired by scikit-learn <> and focuses on bringing probabilistic machine learning to non-specialists. It uses a syntax that mimics scikit-learn. Emphasis is put on ease of use, productivity, flexibility, performance, documentation, and an API consistent with scikit-learn. It depends on scikit-learn and PyMC3 <> and is distributed under the new BSD-3 license, encouraging its use in both academia and industry.

Users can now have calibrated quantities of uncertainty in their models using powerful inference algorithms -- such as MCMC or Variational inference -- provided by PyMC3 <>_. See :doc:why for a more detailed description of why pymc-learn was created.

.. NOTE:: pymc-learn leverages and extends the Base template provided by the PyMC3 Models project:

Transitioning from PyMC3 to PyMC4 ..................................

.. raw:: html

    <blockquote class="twitter-tweet" data-lang="en"><p lang="en" dir="ltr">.<a href="">@pymc_learn</a> has been following closely the development of <a href=";ref_src=twsrc%5Etfw">#PyMC4</a> with the aim of switching its backend from <a href=";ref_src=twsrc%5Etfw">#PyMC3</a> to PyMC4 as the latter grows to maturity. Core devs are invited. Here&#39;s the tentative roadmap for PyMC4: <a href=""></a> cc <a href="">@pymc_devs</a> <a href=""></a></p>&mdash; pymc-learn (@pymc_learn) <a href="">November 5, 2018</a></blockquote> <script async src="" charset="utf-8"></script>

Familiar user interface

pymc-learn mimics scikit-learn. You don't have to completely rewrite your scikit-learn ML code.

.. code-block:: python

from sklearn.linear_model \                         from pmlearn.linear_model \
  import LinearRegression                             import LinearRegression
lr = LinearRegression()                             lr = LinearRegression(), y)                              , y)

The difference between the two models is that pymc-learn estimates model parameters using Bayesian inference algorithms such as MCMC or variational inference. This produces calibrated quantities of uncertainty for model parameters and predictions.

Quick Install

pymc-learn requires a working Python interpreter (2.7 or 3.5+). It is 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), pymc-learn itself can be installed in one line using pip:

You can install pymc-learn from PyPi using pip as follows:

.. code-block:: bash

pip install pymc-learn

Or from source as follows:

.. code-block:: bash

pip install git+

.. CAUTION:: pymc-learn is under heavy development.

It is recommended installing pymc-learn in a Conda environment because it provides Math Kernel Library <> (MKL) routines to accelerate math functions. If you are having trouble, try using a distribution of Python that includes these packages like Anaconda <>.

Dependencies ................

pymc-learn is tested on Python 2.7, 3.5 & 3.6 and depends on Theano, PyMC3, Scikit-learn, NumPy, SciPy, and Matplotlib (see requirements.txt for version information).

Quick Start

.. code-block:: python

# For regression using Bayesian Nonparametrics
>>> from sklearn.datasets import make_friedman2
>>> from pmlearn.gaussian_process import GaussianProcessRegressor
>>> from pmlearn.gaussian_process.kernels import DotProduct, WhiteKernel
>>> X, y = make_friedman2(n_samples=500, noise=0, random_state=0)
>>> kernel = DotProduct() + WhiteKernel()
>>> gpr = GaussianProcessRegressor(kernel=kernel).fit(X, y)
>>> gpr.score(X, y)
>>> gpr.predict(X[:2,:], return_std=True)
(array([653.0..., 592.1...]), array([316.6..., 316.6...]))

Scales to Big Data & Complex Models

Recent research has led to the development of variational inference algorithms that are fast and almost as flexible as MCMC. For instance Automatic Differentation Variational Inference (ADVI) is illustrated in the code below.

.. code-block:: python

from pmlearn.neural_network import MLPClassifier
model = MLPClassifier(), y_train, inference_type="advi")

Instead of drawing samples from the posterior, these algorithms fit a distribution (e.g. normal) to the posterior turning a sampling problem into an optimization problem. ADVI is provided PyMC3.

Citing pymc-learn

To cite pymc-learn in publications, please use the following::

Emaasit, Daniel (2018). Pymc-learn: Practical probabilistic machine learning in Python. arXiv preprint arXiv:1811.00542.

Or using BibTex as follows:

.. code-block:: latex

  title={Pymc-learn: Practical probabilistic machine learning in {P}ython},
  author={Emaasit, Daniel and others},
  journal={arXiv preprint arXiv:1811.00542},

If you want to cite pymc-learn for its API, you may also want to consider this reference::

Carlson, Nicole (2018). Custom PyMC3 models built on top of the scikit-learn API.

Or using BibTex as follows:

.. code-block:: latex

  title={pymc3_models: Custom PyMC3 models built on top of the scikit-learn API,
  author={Carlson, Nicole},

License ..............

New BSD-3 license <>__


Getting Started

  • :doc:install
  • :doc:support
  • :doc:why

.. toctree:: :maxdepth: 1 :hidden: :caption: Getting Started

install.rst support.rst why.rst

User Guide

The main documentation. This contains an in-depth description of all models and how to apply them.

  • :doc:user_guide

.. toctree:: :maxdepth: 1 :hidden: :caption: User Guide



Pymc-learn provides probabilistic models for machine learning, in a familiar scikit-learn syntax.

  • :doc:regression
  • :doc:classification
  • :doc:mixture
  • :doc:neural_networks
  • :doc:api

.. toctree:: :maxdepth: 1 :hidden: :caption: Examples

regression.rst classification.rst mixture.rst neural_networks.rst

API Reference

pymc-learn leverages and extends the Base template provided by the PyMC3 Models project:

  • :doc:api

.. toctree:: :maxdepth: 1 :hidden: :caption: API Reference


Help & reference

  • :doc:develop
  • :doc:support
  • :doc:changelog
  • :doc:cite

.. toctree:: :maxdepth: 1 :hidden: :caption: Help & reference

develop.rst support.rst changelog.rst cite.rst

.. |Binder| image::;base64,iVBORw0KGgoAAAANSUhEUgAAAFkAAABZCAMAAABi1XidAAAB8lBMVEX///9XmsrmZYH1olJXmsr1olJXmsrmZYH1olJXmsr1olJXmsrmZYH1olL1olJXmsr1olJXmsrmZYH1olL1olJXmsrmZYH1olJXmsr1olL1olJXmsrmZYH1olL1olJXmsrmZYH1olL1olL0nFf1olJXmsrmZYH1olJXmsq8dZb1olJXmsrmZYH1olJXmspXmspXmsr1olL1olJXmsrmZYH1olJXmsr1olL1olJXmsrmZYH1olL1olLeaIVXmsrmZYH1olL1olL1olJXmsrmZYH1olLna31Xmsr1olJXmsr1olJXmsrmZYH1olLqoVr1olJ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VnIlQQTvxJf8ip7VgjZjyVPrjw1te5otM7RmP7xm+sK2Gv9I8Gi++BRbEkR9EBw8zRUcKxwp73xkaLiqQb+kGduJTNHG72zcW9LoJgqQxpP3/Tj//c3yB0tqzaml05/+orHLksVO+95kX7/7qgJvnjlrfr2Ggsyx0eoy9uPzN5SPd86aXggOsEKW2Prz7du3VID3/tzs/sSRs2w7ovVHKtjrX2pd7ZMlTxAYfBAL9jiDwfLkq55Tm7ifhMlTGPyCAs7RFRhn47JnlcB9RM5T97ASuZXIcVNuUDIndpDbdsfrqsOppeXl5Y+XVKdjFCTh+zGaVuj0d9zy05PPK3QzBamxdwtTCrzyg/2Rvf2EstUjordGwa/kx9mSJLr8mLLtCW8HHGJc2R5hS219IiF6PnTusOqcMl57gm0Z8kanKMAQg0qSyuZfn7zItsbGyO9QlnxY0eCuD1XL2ys/MsrQhltE7Ug0uFOzufJFE2PxBo/YAx8XPPdDwWN0MrDRYIZF0mSMKCNHgaIVFoBbNoLJ7tEQDKxGF0kcLQimojCZopv0OkNOyWCCg9XMVAi7ARJzQdM2QUh0gmBozjc3Skg6dSBRqDGYSUOu66Zg+I2fNZs/M3/f/Grl/XnyF1Gw3VKCez0PN5IUfFLqvgUN4C0qNqYs5YhPL+aVZYDE4IpUk57oSFnJm4FyCqqOE0jhY2SMyLFoo56zyo6becOS5UVDdj7Vih0zp+tcMhwRpBeLyqtIjlJKAIZSbI8SGSF3k0pA3mR5tHuwPFoa7N7reoq2bqCsAk1HqCu5uvI1n6JuRXI+S1Mco54YmYTwcn6Aeic+kssXi8XpXC4V3t7/ADuTNKaQJdScAAAAAElFTkSuQmCC :target:

.. |Travis| image:: :target:

.. |Coverage| image:: :target:

.. |Python27| image:: :target:

.. |Python36| image:: :target:

.. |Docs| image:: :target: :alt: Documentation Status

.. |License| image:: :alt: :target:

.. |Pypi| image:: :target:

.. |status| image::

Rate & Review

Great Documentation0
Easy to Use0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Unwelcoming Community0