pymc

Bayesian modeling with PyMC. Build hierarchical models, MCMC (NUTS), variational inference, LOO/WAIC comparison, posterior checks, for probabilistic programming and inference.

Install

Hot:5

Download and extract to your skills directory

Copy command and send to AI Agent for auto-install:

Download and install this skill https://openskills.cc/api/download?slug=k-dense-ai-skills-pymc&locale=en&source=copy

PyMC Bayesian Modeling Skills

Skill Overview


PyMC provides a complete Bayesian modeling workflow to help you build probabilistic models with Python, perform MCMC sampling, run model diagnostics, and carry out predictive inference. It is suitable for uncertainty quantification in scientific research, data analysis, and machine learning.

Use Cases


  • Scientific Research and Data Analysis: When you need to build Bayesian models to quantify uncertainty in research, handle small datasets or missing data, or provide probabilistic interpretations for scientific hypotheses, PyMC offers an end-to-end workflow from data preparation to model validation.
  • Hierarchical Data Modeling: When your data has grouped or multi-level structure (e.g., repeated measurements or geographically clustered data) and you need hierarchical models to capture both within-group and between-group variability, PyMC’s non-centered parameterization can effectively prevent sampling divergences.
  • Model Comparison and Prediction: When you need to compare multiple competing models, perform posterior predictive checks, or generate predictions with uncertainty intervals, PyMC’s integrated LOO/WAIC model comparison and prediction tools provide rigorous statistical inference support.
  • Core Features


  • Bayesian Model Building and Sampling: Supports many model types such as linear regression, logistic regression, Poisson regression, and time series. Uses the NUTS (No-U-Turn Sampler) algorithm for efficient MCMC sampling, and provides variational inference (ADVI) as a fast approximation option.
  • Model Diagnostics and Validation: Offers automated diagnostics to check R-hat, effective sample size (ESS), and divergence issues. Supports prior predictive checks and posterior predictive checks to ensure the reliability and robustness of model fits.
  • Probability Distributions Library and Templates: Includes a complete reference guide for probability distributions, covering continuous, discrete, multivariate, and time-series distributions. Also provides full code templates for linear regression and hierarchical models to quickly start Bayesian analysis projects.
  • FAQs

    What Python version and dependencies does PyMC require?


    PyMC 6.0.1 requires Python 3.12 or higher and uses PyTensor 3 as the computational graph backend. It is recommended to install with uv pip install "pymc[nutpie]==6.0.1". The nutpie extension provides a faster Rust/Numba NUTS implementation. If you need to use NumPyro or the BlackJAX sampler, you must install the compatible JAX dependencies separately.

    How can I resolve divergence issues in MCMC sampling?


    Divergences are typically addressed with the following approaches: increase target_accept to 0.95 or higher; use non-centered parameterization for hierarchical models; add stronger prior constraints to parameters; and check whether the model specification is incorrect. If the problem persists, you may need to reparameterize the model or use variational inference for initialization.

    How should I choose between LOO and WAIC for Bayesian model comparison?


    LOO (leave-one-out cross-validation) is usually more accurate, but you should check Pareto-k values (reliable when k < 0.7). WAIC (Widely Applicable Information Criterion) is faster to compute and is suitable for large-scale model comparisons. When ΔLOO < 2 the models are similar—choose the simpler one. When ΔLOO > 10 there is strong evidence for the better model. For both, you must include log_likelihood=True during fitting.