Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Bayesian Analysis with Python
Bayesian Analysis with Python

Bayesian Analysis with Python: A practical guide to probabilistic modeling , Third Edition

eBook
€26.98 €29.99
Paperback
€37.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

Bayesian Analysis with Python

Chapter 1
Thinking Probabilistically

Probability theory is nothing but common sense reduced to calculation. – Pierre Simon Laplace

In this chapter, we will learn about the core concepts of Bayesian statistics and some of the instruments in the Bayesian toolbox. We will use some Python code, but this chapter will be mostly theoretical; most of the concepts we will see here will be revisited many times throughout this book. This chapter, being heavy on the theoretical side, is perhaps a little anxiogenic for the coder in you, but I think it will ease the path to effectively applying Bayesian statistics to your problems.

In this chapter, we will cover the following topics:

  • Statistical modeling

  • Probabilities and uncertainty

  • Bayes’ theorem and statistical inference

  • Single-parameter inference and the classic coin-flip problem

  • Choosing priors and why people often don’t like them but should

  • Communicating a Bayesian analysis

1.1 Statistics, models, and this book’s approach

Statistics is about collecting, organizing, analyzing, and interpreting data, and hence statistical knowledge is essential for data analysis. Two main statistical methods are used in data analysis:

  • Exploratory Data Analysis (EDA): This is about numerical summaries, such as the mean, mode, standard deviation, and interquartile ranges. EDA is also about visually inspecting the data, using tools you may be already familiar with, such as histograms and scatter plots.

  • Inferential statistics: This is about making statements beyond the current data. We may want to understand some particular phenomenon, maybe we want to make predictions for future (yet unobserved) data points, or we need to choose among several competing explanations for the same set of observations. In summary, inferential statistics allow us to draw meaningful insights from a limited set of data and make informed decisions based on the results of our analysis.

A Match Made in Heaven

The focus of this book is on how to perform Bayesian inferential statistics, but we will also use ideas from EDA to summarize, interpret, check, and communicate the results of Bayesian inference.

Most introductory statistical courses, at least for non-statisticians, are taught as a collection of recipes that go like this: go to the statistical pantry, pick one tin can and open it, add data to taste, and stir until you obtain a consistent p-value, preferably under 0.05. The main goal of these courses is to teach you how to pick the proper can. I never liked this approach, mainly because the most common result is a bunch of confused people unable to grasp, even at the conceptual level, the unity of the different learned methods. We will take a different approach: we will learn some recipes, but they will be homemade rather than canned food; we will learn how to mix fresh ingredients that will suit different statistical occasions and, more importantly, that will let you apply concepts far beyond the examples in this book.

Taking this approach is possible for two reasons:

  • Ontological: Statistics is a form of modeling unified under the mathematical framework of probability theory. Using a probabilistic approach provides a unified view of what may seem like very disparate methods; statistical methods and machine learning methods look much more similar under the probabilistic lens.

  • Technical: Modern software, such as PyMC, allows practitioners, just like you and me, to define and solve models in a relatively easy way. Many of these models were unsolvable just a few years ago or required a high level of mathematical and technical sophistication.

1.2 Working with data

Data is an essential ingredient in statistics and data science. Data comes from several sources, such as experiments, computer simulations, surveys, and field observations. If we are the ones in charge of generating or gathering the data, it is always a good idea to first think carefully about the questions we want to answer and which methods we will use, and only then proceed to get the data. There is a whole branch of statistics dealing with data collection, known as experimental design. In the era of the data deluge, we can sometimes forget that gathering data is not always cheap. For example, while it is true that the Large Hadron Collider (LHC) produces hundreds of terabytes a day, its construction took years of manual and intellectual labor.

As a general rule, we can think of the process of generating the data as stochastic, because there is ontological, technical, and/or epistemic uncertainty, that is, the system is intrinsically stochastic, there are technical issues adding noise or restricting us from measuring with arbitrary precision, and/or there are conceptual limitations veiling details from us. For all these reasons, we always need to interpret data in the context of models, including mental and formal ones. Data does not speak but through models.

In this book, we will assume that we already have collected the data. Our data will also be clean and tidy, something that’s rarely true in the real world. We will make these assumptions to focus on the subject of this book. I just want to emphasize, especially for newcomers to data analysis, that even when not covered in this book, there are important skills that you should learn and practice to successfully work with data.

A very useful skill when analyzing data is knowing how to write code in a programming language, such as Python. Manipulating data is usually necessary given that we live in a messy world with even messier data, and coding helps to get things done. Even if you are lucky and your data is very clean and tidy, coding will still be very useful since modern Bayesian statistics is done mostly through programming languages such as Python or R. If you want to learn how to use Python for cleaning and manipulating data, you can find a good introduction in Python for Data Analysis by McKinney [2022].

1.3 Bayesian modeling

Models are simplified descriptions of a given system or process that, for some reason, we are interested in. Those descriptions are deliberately designed to capture only the most relevant aspects of the system and not to explain every minor detail. This is one reason a more complex model is not always a better one. There are many different kinds of models; in this book, we will restrict ourselves to Bayesian models. We can summarize the Bayesian modeling process using three steps:

  1. Given some data and some assumptions on how this data could have been generated, we design a model by combining building blocks known as probability distributions. Most of the time these models are crude approximations, but most of the time that’s all we need.

  2. We use Bayes’ theorem to add data to our models and derive the logical consequences of combining the data and our assumptions. We say we are conditioning the model on our data.

  3. We evaluate the model, and its predictions, under different criteria, including the data, our expertise on the subject, and sometimes by comparing it to other models.

In general, we will find ourselves performing these three steps in an iterative non-linear fashion. We will retrace our steps at any given point: maybe we made a silly coding mistake, or we found a way to change the model and improve it, or we realized that we need to add more data or collect a different kind of data.

Bayesian models are also known as probabilistic models because they are built using probabilities. Why probabilities? Because probabilities are a very useful tool to model uncertainty; we even have good arguments to state they are the correct mathematical concept. So let’s take a walk through the garden of forking paths [Borges1944].

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Conduct Bayesian data analysis with step-by-step guidance
  • Gain insight into a modern, practical, and computational approach to Bayesian statistical modeling
  • Enhance your learning with best practices through sample problems and practice exercises
  • Purchase of the print or Kindle book includes a free PDF eBook.

Description

The third edition of Bayesian Analysis with Python serves as an introduction to the main concepts of applied Bayesian modeling using PyMC, a state-of-the-art probabilistic programming library, and other libraries that support and facilitate modeling like ArviZ, for exploratory analysis of Bayesian models; Bambi, for flexible and easy hierarchical linear modeling; PreliZ, for prior elicitation; PyMC-BART, for flexible non-parametric regression; and Kulprit, for variable selection. In this updated edition, a brief and conceptual introduction to probability theory enhances your learning journey by introducing new topics like Bayesian additive regression trees (BART), featuring updated examples. Refined explanations, informed by feedback and experience from previous editions, underscore the book's emphasis on Bayesian statistics. You will explore various models, including hierarchical models, generalized linear models for regression and classification, mixture models, Gaussian processes, and BART, using synthetic and real datasets. By the end of this book, you will possess a functional understanding of probabilistic modeling, enabling you to design and implement Bayesian models for your data science challenges. You'll be well-prepared to delve into more advanced material or specialized statistical modeling if the need arises.

Who is this book for?

If you are a student, data scientist, researcher, or developer looking to get started with Bayesian data analysis and probabilistic programming, this book is for you. The book is introductory, so no previous statistical knowledge is required, although some experience in using Python and scientific libraries like NumPy is expected.

What you will learn

  • Build probabilistic models using PyMC and Bambi
  • Analyze and interpret probabilistic models with ArviZ
  • Acquire the skills to sanity-check models and modify them if necessary
  • Build better models with prior and posterior predictive checks
  • Learn the advantages and caveats of hierarchical models
  • Compare models and choose between alternative ones
  • Interpret results and apply your knowledge to real-world problems
  • Explore common models from a unified probabilistic perspective
  • Apply the Bayesian framework's flexibility for probabilistic thinking

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Jan 31, 2024
Length: 394 pages
Edition : 3rd
Language : English
ISBN-13 : 9781805125419
Category :
Languages :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Jan 31, 2024
Length: 394 pages
Edition : 3rd
Language : English
ISBN-13 : 9781805125419
Category :
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 119.97
Transformers for Natural Language Processing and Computer Vision
€41.99
Mastering NLP from Foundations to LLMs
€39.99
Bayesian Analysis with Python
€37.99
Total 119.97 Stars icon

Table of Contents

14 Chapters
Chapter 1 Thinking Probabilistically Chevron down icon Chevron up icon
Chapter 2 Programming Probabilistically Chevron down icon Chevron up icon
Chapter 3 Hierarchical Models Chevron down icon Chevron up icon
Chapter 4 Modeling with Lines Chevron down icon Chevron up icon
Chapter 5 Comparing Models Chevron down icon Chevron up icon
Chapter 6 Modeling with Bambi Chevron down icon Chevron up icon
Chapter 7 Mixture Models Chevron down icon Chevron up icon
Chapter 8 Gaussian Processes Chevron down icon Chevron up icon
Chapter 9 Bayesian Additive Regression Trees Chevron down icon Chevron up icon
Chapter 10 Inference Engines Chevron down icon Chevron up icon
Chapter 11 Where to Go Next Chevron down icon Chevron up icon
Bibliography Chevron down icon Chevron up icon
Other Books You May Enjoy Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.7
(23 Ratings)
5 star 78.3%
4 star 17.4%
3 star 0%
2 star 0%
1 star 4.3%
Filter icon Filter
Top Reviews

Filter reviews by




Jon Barley Nov 08, 2024
Full star icon Full star icon Full star icon Full star icon Full star icon 5
An excellent introduction into practical Bayesian analysis with many illuminating examples.
Feefo Verified review Feefo
RP Aug 13, 2024
Full star icon Full star icon Full star icon Full star icon Full star icon 5
If you had to buy just one book on Bayesian analysis, this is the one to get. It takes a lot of skill to write a concise, readable book on such a complicated topic.
Amazon Verified review Amazon
ben Jun 18, 2024
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Osvaldo Martin’s “Bayesian Analysis with Python” is an exceptional resource for anyone looking to delve into the world of Bayesian inference using Python. The book is tailored for readers who possess a basic understanding of Python but may not have extensive knowledge of statistics or Bayesian methods. This accessibility makes it an ideal starting point for beginners while still offering depth for more experienced readers.One of the book’s standout features is its practical approach. Each chapter concludes with exercises that reinforce the concepts covered, and there is even a dedicated Discord space provided by the publisher for further discussion and learning. The introductory chapters lay a strong foundation in both theoretical and computational aspects of Bayesian inference, with “Thinking Probabilistically” and “Programming Probabilistically” offering a seamless blend of theory and hands-on coding with PyMC, one of the leading probabilistic programming languages.For those new to the subject, reading the first two chapters in tandem can be particularly beneficial, combining conceptual understanding with computational implementation. Subsequent chapters delve into specific modeling approaches, such as hierarchical models, generalized linear models, mixture models, Gaussian processes, and Bayesian adaptive regression trees (BART). Each of these chapters provides valuable insights and practical knowledge that can be directly applied to real-world problems.The book also covers essential topics in practice, including model comparison and evaluation, which are crucial for any data scientist. The chapter on Bambi is especially noteworthy, demonstrating how formula syntax can be used to efficiently build PyMC models, accompanied by clear visual representations of the models using Graphviz.Additionally, the chapter on inference engines serves as a comprehensive reference for understanding the mechanics behind Bayesian samplers and inference methods, making it a valuable resource for both teaching and practical application.Overall, “Bayesian Analysis with Python” is an excellent book for anyone interested in Bayesian inference. It successfully bridges the gap between core concepts and practical implementation, and it does so using the robust Bayesian “tech stack” of PyMC, ArviZ, and Bambi. The book also provides an excellent list of further resources, including books, code repositories, paid courses, and open-source community hangouts, making it a well-rounded and highly recommended read for aspiring Bayesian analysts.
Amazon Verified review Amazon
Banachan Mar 06, 2024
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This is a great practical guide to probabilistic modeling using Python, especially for those interested in or working with Bayesian data analysis. It covers a broad range of topics, from basic concepts to more advanced modeling techniques, so I can see it being an invaluable resource to both practitioners and students.The book provides a thorough exploration, specifically on addressing Bayesian analysis techniques. It's quite an enjoyable and comprehensive guide for both beginners and advanced practitioners. Good emphasis on fundamentals, then transitions to more complex concepts and application. I thought it provided a good balance between theory and practical skills.Summary of pros are that it encourages hands-on learning, with wide coverage on the subject. Doesn't hurt that it's an updated edition with up-to-date approaches. Some of the cons are that it might be complex in some sections for pure beginners. Code examples are mostly in Python (so I guess this could be a con or pro depending on how look at it).I still like that it has a lot of examples, code snippets, and real-world scenarios included, with good explanations. Covers model construction, prior selection, model comparison, to predictive analysis. I surmise that this allows for a variety of learning needs for most folks. Author style is both authoritative and accessible. I would recommend this book for academia, professional development, or just for personal interest in data science.
Amazon Verified review Amazon
Nicole M Radziwill May 07, 2024
Full star icon Full star icon Full star icon Full star icon Full star icon 5
While Python is my go-to language for things like NLP, I usually use R for everything else. After spending a solid long weekend with Martin's new book "Bayesian Analysis with Python" I can confirm that this book will be just what ONE audience needs, but may disappoint others. As a gentle introduction to Bayesian approaches for people who are well versed in intro statistics and have a solid foundation in Python, it's perfect. But if you're missing that mathematical statistics background (or if you're rusty on Python) this book may present a struggle.As a result, this is five stars for the target audience and four for the other audiences.The writing is clear and easy to follow, but sometimes encourages you to "review the code for understanding" where the text could have explained each of the lines of code in sequence. The book also assumes that the reader has a fundamental understanding of distributions and mathematical notation, which may not be the case for all programmers or data analysts. As a professor this would have been a great book to use from an introductory Bayesian methods course for juniors or seniors in STEM with at least one or two semesters of Python. For this group, the book is particularly strong, because it takes a computation-first approach but fills in the gaps with just enough theory.Highlights include:- There is a simple discussion on ROPE and loss functions that is valuable- There is a good discussion about how to do linear regression the Bayesian way (hint: all parameters treated as priors)- Some interesting mixture models using the Palmer Penguins dataset- The best part was the MCMC with Metropolis-Hastings to calculate the value of piDO buy this book if you have a solid foundation in Python (and a Python environment already set up) and want to spend a few weeks (or a couple months) expanding your understanding into building and running simple Bayesian models. If you have the time to spend, this will deepen your understanding.DO NOT buy this book if you are a programmer who needs to start building Bayesian models at work within the next couple days! It's not going to help you work that next ticket in the queue.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.