SlideShare ist ein Scribd-Unternehmen logo
1 von 62
Bayesian Workflow with
PyMC and ArviZ
Corrie Bartelheimer
Data Scientist at Europace AG
@corrieaar
First, the problem
First, the problem
First, the problem
First, the problem
First, the problem
First, the problem
First, the problem
First, the problem
Solution:
Hierarchical Bayesian Model
Solution: Hierarchical Bayesian Model
Solution: Hierarchical Bayesian Model
Solution: Hierarchical Bayesian Model
Solution: Hierarchical Bayesian Model
Solution: Hierarchical Bayesian Model
Getting this into Python
import pymc3 as pm
with pm.Model() as lin_model:
α = pm.Normal("α", 0, 100)
β = pm.Normal("β", 0, 100)
σ = pm.Exponential("σ", 1/100)
μ = α + β*d["area"]
y = pm.Normal("y", μ, σ,
observed=d["price"])
Getting this into Python: PyMC3
import pymc3 as pm
with pm.Model() as lin_model:
α = pm.Normal("α", 0, 100)
β = pm.Normal("β", 0, 100)
σ = pm.Exponential("σ", 1/100)
μ = α + β*d["area"]
y = pm.Normal("y", μ, σ,
observed=d["price"])
Getting this into Python: PyMC3
import pymc3 as pm
with pm.Model() as lin_model:
α = pm.Normal("α", 0, 100)
β = pm.Normal("β", 0, 100)
σ = pm.Exponential("σ", 1/100)
μ = α + β*d["area"]
y = pm.Normal("y", μ, σ,
observed=d["price"])
Getting this into Python: PyMC3
Getting this into Python: PyMC3
import pymc3 as pm
with pm.Model() as lin_model:
α = pm.Normal("α", 0, 100)
β = pm.Normal("β", 0, 100)
σ = pm.Exponential("σ", 1/100)
μ = α + β*d["area"]
y = pm.Normal("y", μ, σ,
observed=d["price"])
with pm.Model() as hier_model:
μ_α = pm.Normal("μ_α", 0, 100)
μ_β = ...
σ = pm.Exponential("σ", 1/100)
σ_α = σ_β = ...
α = pm.Normal("α", μ_α, σ_α,
shape=num_zip)
β = pm.Normal("β", μ_β, σ_β,
shape=num_zip)
μ = α[d["zip"]] + β[d["zip"]]*d["area"]
y = pm.Normal("y", μ, σ,
observed=d["price"])
Getting this into Python: PyMC3
with pm.Model() as hier_model:
μ_α = pm.Normal("μ_α", 0, 100)
μ_β = ...
σ = pm.Exponential("σ", 1/100)
σ_α = σ_β = ...
α = pm.Normal("α", μ_α, σ_α,
shape=num_zip)
β = pm.Normal("β", μ_β, σ_β,
shape=num_zip)
μ = α[d["zip"]] + β[d["zip"]]*d["area"]
y = pm.Normal("y", μ, σ,
observed=d["price"])
Getting this into Python: PyMC3
with pm.Model() as hier_model:
μ_α = pm.Normal("μ_α", 0, 100)
μ_β = ...
σ = pm.Exponential("σ", 1/100)
σ_α = σ_β = ...
α = pm.Normal("α", μ_α, σ_α,
shape=num_zip)
β = pm.Normal("β", μ_β, σ_β,
shape=num_zip)
μ = α[d["zip"]] + β[d["zip"]]*d["area"]
y = pm.Normal("y", μ, σ,
observed=d["price"])
Getting this into Python: PyMC3
with pm.Model() as hier_model:
μ_α = pm.Normal("μ_α", 0, 100)
μ_β = ...
σ = pm.Exponential("σ", 1/100)
σ_α = σ_β = ...
α = pm.Normal("α", μ_α, σ_α,
shape=num_zip)
β = pm.Normal("β", μ_β, σ_β,
shape=num_zip)
μ = α[d["zip"]] + β[d["zip"]]*d["area"]
y = pm.Normal("y", μ, σ,
observed=d["price"])
Getting this into Python: PyMC3
What about the priors?
What about the priors?
What about the priors?
with model:
prior = pm.sample_prior_predictive()
with model:
prior = pm.sample_prior_predictive()
What about the priors?
with model:
prior = pm.sample_prior_predictive()
What about the priors?
with model:
prior = pm.sample_prior_predictive()
What about the priors?
What about the priors?
What about the priors?
What about the priors?
What about the priors?
What about the priors?
with pm.Model() as hier_model:
μ_α = pm.Normal("μ_α", 0, 20)
μ_β = pm.Normal("μ_β", 0, 5)
σ = pm.Exponential("σ", 1/5)
σ_α = σ_β = ...
α = pm.Normal("α", μ_α, σ_α,
shape=num_zip)
β = pm.Normal("β", μ_β, σ_β,
shape=num_zip)
μ = α[d["zip"]] + β[d["zip"]]*d["area"]
y = pm.Normal("y", μ, σ,
observed=d["price"])
trace = pm.sample()
What about the priors?
Did it converge?
Did it converge?
import arviz as az
az.plot_trace(trace)
Did it converge?
Did it converge?
Some Bad Examples
Did it converge?
Some Bad Examples
Did it converge?
Some Bad Examples
Did it converge?
Some Bad Examples
Did it converge?
az.summary(trace)
Did it converge?
az.summary(trace)
Did it converge?
az.summary(trace)
Did it converge?
az.summary(trace)
Did it converge?
Rhat statistic smaller
1.05?
Effective sample size / iterations
greater 10%?
Monte Carlo se / posterior sd
smaller 10%?
How good does my model fit the
data?
How good does my model fit the data?
with hier_model:
posterior_predictive = pm.sample_posterior_predictive(trace)
How good does my model fit the data?
How good does my model fit the data?
How good does my model fit the data?
Results, please!
Results, please!
Results, please!
Results, please!
Results, please!
What’s next?
What’s next?
● Iterate!
● More predictors!
○ Year of construction
○ House type
○ ...
● More hierarchies!
● Add group predictors!
○ Percentage of green areas
○ Economical indices
● Try different likelihoods
● Probably save more money...
Further resources Richard McElreath: Statistical Rethinking
- Port to PyMC3
Prior Recommendation by Stan Team
Michael Betancourts Case Studies
BerlinBayesians
Icons by icons8
Thanks!
@corrieaar
corriebar
Code and Notebooks
www.samples-of-thoughts.com
Icons by icons8

Weitere ähnliche Inhalte

Was ist angesagt?

Particle Swarm Optimization
Particle Swarm OptimizationParticle Swarm Optimization
Particle Swarm Optimization
Stelios Petrakis
 
Bat algorithm explained. slides ppt pptx
Bat algorithm explained. slides ppt pptxBat algorithm explained. slides ppt pptx
Bat algorithm explained. slides ppt pptx
Mahdi Atawneh
 
Introduction to Deep Learning, Keras, and TensorFlow
Introduction to Deep Learning, Keras, and TensorFlowIntroduction to Deep Learning, Keras, and TensorFlow
Introduction to Deep Learning, Keras, and TensorFlow
Sri Ambati
 
Machine Learning and Stochastic Geometry: Statistical Frameworks Against Unce...
Machine Learning and Stochastic Geometry: Statistical Frameworks Against Unce...Machine Learning and Stochastic Geometry: Statistical Frameworks Against Unce...
Machine Learning and Stochastic Geometry: Statistical Frameworks Against Unce...
Koji Yamamoto
 
matlab code for channel estimation for ofdm
matlab code for channel estimation for ofdmmatlab code for channel estimation for ofdm
matlab code for channel estimation for ofdm
Gyana Ranjan Mati
 
Fuzzy Logic Ppt
Fuzzy Logic PptFuzzy Logic Ppt
Fuzzy Logic Ppt
rafi
 

Was ist angesagt? (20)

Optimization in Deep Learning
Optimization in Deep LearningOptimization in Deep Learning
Optimization in Deep Learning
 
Optimization for Deep Learning
Optimization for Deep LearningOptimization for Deep Learning
Optimization for Deep Learning
 
Bat algorithm and applications
Bat algorithm and applicationsBat algorithm and applications
Bat algorithm and applications
 
Stochastic Gradient Decent (SGD).pptx
Stochastic Gradient Decent (SGD).pptxStochastic Gradient Decent (SGD).pptx
Stochastic Gradient Decent (SGD).pptx
 
Particle Swarm Optimization
Particle Swarm OptimizationParticle Swarm Optimization
Particle Swarm Optimization
 
Efficient estimation of word representations in vector space (2013)
Efficient estimation of word representations in vector space (2013)Efficient estimation of word representations in vector space (2013)
Efficient estimation of word representations in vector space (2013)
 
Bat algorithm explained. slides ppt pptx
Bat algorithm explained. slides ppt pptxBat algorithm explained. slides ppt pptx
Bat algorithm explained. slides ppt pptx
 
Introduction to Deep Learning, Keras, and TensorFlow
Introduction to Deep Learning, Keras, and TensorFlowIntroduction to Deep Learning, Keras, and TensorFlow
Introduction to Deep Learning, Keras, and TensorFlow
 
Variational Autoencoder Tutorial
Variational Autoencoder Tutorial Variational Autoencoder Tutorial
Variational Autoencoder Tutorial
 
Text generation and_advanced_topics
Text generation and_advanced_topicsText generation and_advanced_topics
Text generation and_advanced_topics
 
Machine Learning and Data Mining: 12 Classification Rules
Machine Learning and Data Mining: 12 Classification RulesMachine Learning and Data Mining: 12 Classification Rules
Machine Learning and Data Mining: 12 Classification Rules
 
Path loss models
Path loss modelsPath loss models
Path loss models
 
Hyperparameter Optimization for Machine Learning
Hyperparameter Optimization for Machine LearningHyperparameter Optimization for Machine Learning
Hyperparameter Optimization for Machine Learning
 
Introduction of Deep Learning
Introduction of Deep LearningIntroduction of Deep Learning
Introduction of Deep Learning
 
Machine Learning and Stochastic Geometry: Statistical Frameworks Against Unce...
Machine Learning and Stochastic Geometry: Statistical Frameworks Against Unce...Machine Learning and Stochastic Geometry: Statistical Frameworks Against Unce...
Machine Learning and Stochastic Geometry: Statistical Frameworks Against Unce...
 
Alpha-beta pruning (Artificial Intelligence)
Alpha-beta pruning (Artificial Intelligence)Alpha-beta pruning (Artificial Intelligence)
Alpha-beta pruning (Artificial Intelligence)
 
Introduction to Artificial Neural Network
Introduction to Artificial Neural Network Introduction to Artificial Neural Network
Introduction to Artificial Neural Network
 
matlab code for channel estimation for ofdm
matlab code for channel estimation for ofdmmatlab code for channel estimation for ofdm
matlab code for channel estimation for ofdm
 
08 Machine Learning Maximum Aposteriori
08 Machine Learning Maximum Aposteriori08 Machine Learning Maximum Aposteriori
08 Machine Learning Maximum Aposteriori
 
Fuzzy Logic Ppt
Fuzzy Logic PptFuzzy Logic Ppt
Fuzzy Logic Ppt
 

Ähnlich wie Bayesian workflow with PyMC3 and ArviZ

Real World Haskell: Lecture 5
Real World Haskell: Lecture 5Real World Haskell: Lecture 5
Real World Haskell: Lecture 5
Bryan O'Sullivan
 
Useful javascript
Useful javascriptUseful javascript
Useful javascript
Lei Kang
 
Raices de ecuaciones
Raices de ecuacionesRaices de ecuaciones
Raices de ecuaciones
Natalia
 

Ähnlich wie Bayesian workflow with PyMC3 and ArviZ (20)

Python 03-parameters-graphics.pptx
Python 03-parameters-graphics.pptxPython 03-parameters-graphics.pptx
Python 03-parameters-graphics.pptx
 
Applied machine learning for search engine relevance 3
Applied machine learning for search engine relevance 3Applied machine learning for search engine relevance 3
Applied machine learning for search engine relevance 3
 
Tech-1.pptx
Tech-1.pptxTech-1.pptx
Tech-1.pptx
 
Byterun, a Python bytecode interpreter - Allison Kaptur at NYCPython
Byterun, a Python bytecode interpreter - Allison Kaptur at NYCPythonByterun, a Python bytecode interpreter - Allison Kaptur at NYCPython
Byterun, a Python bytecode interpreter - Allison Kaptur at NYCPython
 
LET US C (5th EDITION) CHAPTER 2 ANSWERS
LET US C (5th EDITION) CHAPTER 2 ANSWERSLET US C (5th EDITION) CHAPTER 2 ANSWERS
LET US C (5th EDITION) CHAPTER 2 ANSWERS
 
Python for Scientific Computing -- Ricardo Cruz
Python for Scientific Computing -- Ricardo CruzPython for Scientific Computing -- Ricardo Cruz
Python for Scientific Computing -- Ricardo Cruz
 
Python grass
Python grassPython grass
Python grass
 
Approximate Bayesian computation for the Ising/Potts model
Approximate Bayesian computation for the Ising/Potts modelApproximate Bayesian computation for the Ising/Potts model
Approximate Bayesian computation for the Ising/Potts model
 
Introduction to NumPy (PyData SV 2013)
Introduction to NumPy (PyData SV 2013)Introduction to NumPy (PyData SV 2013)
Introduction to NumPy (PyData SV 2013)
 
Introduction to NumPy
Introduction to NumPyIntroduction to NumPy
Introduction to NumPy
 
하스켈 프로그래밍 입문 3
하스켈 프로그래밍 입문 3하스켈 프로그래밍 입문 3
하스켈 프로그래밍 입문 3
 
Basic Calculus in R.
Basic Calculus in R. Basic Calculus in R.
Basic Calculus in R.
 
Allison Kaptur: Bytes in the Machine: Inside the CPython interpreter, PyGotha...
Allison Kaptur: Bytes in the Machine: Inside the CPython interpreter, PyGotha...Allison Kaptur: Bytes in the Machine: Inside the CPython interpreter, PyGotha...
Allison Kaptur: Bytes in the Machine: Inside the CPython interpreter, PyGotha...
 
Pythonbrasil - 2018 - Acelerando Soluções com GPU
Pythonbrasil - 2018 - Acelerando Soluções com GPUPythonbrasil - 2018 - Acelerando Soluções com GPU
Pythonbrasil - 2018 - Acelerando Soluções com GPU
 
Monoids - Part 1 - with examples using Scalaz and Cats
Monoids - Part 1 - with examples using Scalaz and CatsMonoids - Part 1 - with examples using Scalaz and Cats
Monoids - Part 1 - with examples using Scalaz and Cats
 
Bayesian Inference : Kalman filter 에서 Optimization 까지 - 김홍배 박사님
Bayesian Inference : Kalman filter 에서 Optimization 까지 - 김홍배 박사님Bayesian Inference : Kalman filter 에서 Optimization 까지 - 김홍배 박사님
Bayesian Inference : Kalman filter 에서 Optimization 까지 - 김홍배 박사님
 
Image Restoration (Digital Image Processing)
Image Restoration (Digital Image Processing)Image Restoration (Digital Image Processing)
Image Restoration (Digital Image Processing)
 
Real World Haskell: Lecture 5
Real World Haskell: Lecture 5Real World Haskell: Lecture 5
Real World Haskell: Lecture 5
 
Useful javascript
Useful javascriptUseful javascript
Useful javascript
 
Raices de ecuaciones
Raices de ecuacionesRaices de ecuaciones
Raices de ecuaciones
 

Kürzlich hochgeladen

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Kürzlich hochgeladen (20)

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 

Bayesian workflow with PyMC3 and ArviZ

Hinweis der Redaktion

  1. Meetup Icons by icons8
  2. Photo by Crawford Jolly on Unsplash Twitter and Github Icons by icons8