Basics of Bayesian statistics and practice of Bayesian estimation using Python | newji
製造業の見積・発注クラウド

その単価は妥当か。
AI が根拠付きで分析。

相見積の比較も発注も進捗管理も、ひとつの画面に。

サービス資料をダウンロードPDF・無料/1分で受け取れます

投稿日:2024年12月20日

Basics of Bayesian statistics and practice of Bayesian estimation using Python

What is Bayesian Statistics?

💡 こうした調達・受発注の属人化、Newji one なら「ひとつの画面」で解決。見積依頼から発注・進捗・承認までAIが下支えします。
サービス資料を見る(無料)→

Bayesian statistics is a branch of statistics based on Bayes’ Theorem, which provides a probabilistic framework for updating beliefs based on new evidence or data.
It contrasts with classical or frequentist statistics by incorporating prior knowledge or beliefs into the statistical analysis.
In Bayesian analysis, probabilities are interpreted as degrees of belief about a hypothesis, rather than long-run frequencies.

Bayesian statistics revolves around the concept of updating our knowledge.
We start with an initial belief or prior distribution about a parameter or hypothesis.
As we gather data, we update this belief using Bayes’ Theorem to obtain a posterior distribution.
This posterior distribution then serves as the new foundation for making predictions or decisions.

Bayes’ Theorem Explained

Bayes’ Theorem is a mathematical formula that describes how to update the probabilities of hypotheses when given new evidence.
Mathematically, it can be expressed as:

P(H|E) = [P(E|H) * P(H)] / P(E)

Where:
– P(H|E) is the posterior probability, or the probability of the hypothesis H given the evidence E.
– P(E|H) is the likelihood, or the probability of observing the evidence E, given that hypothesis H is true.
– P(H) is the prior probability, or the initial probability of hypothesis H before observing the evidence.
– P(E) is the marginal probability, or the probability of observing the evidence under all possible hypotheses.

This theorem is fundamental in the process of Bayesian updating and is central to Bayesian analysis.

Applications of Bayesian Statistics

Bayesian statistics is widely used in various fields due to its flexibility and ability to incorporate prior information.
Some common applications include:

1. Medical Research

In medical research, Bayesian methods can incorporate prior clinical trials or expert opinion into the analysis of new data.
This is particularly useful in drug development, where historical data on drug effects can inform the design of new experiments.

2. Machine Learning

Bayesian methods underpin many machine learning algorithms, such as Bayesian networks and Gaussian processes.
These techniques are used for classification, regression, and clustering tasks, allowing for probabilistic predictions that include uncertainty estimates.

3. Finance

In finance, Bayesian statistics can improve models for stock returns, risk analysis, and portfolio optimization.
Prior beliefs about market conditions can be updated as new financial data becomes available, leading to more adaptive and responsive investment strategies.

4. Environmental Sciences

Researchers in environmental science use Bayesian statistics for modeling the impact of human activities on ecosystems.
By incorporating prior knowledge about environmental systems, Bayesian methods can offer more accurate predictions and assessments.

Bayesian Estimation Using Python

Python is a popular programming language that provides several libraries for Bayesian estimation and modeling.
Here, we’ll discuss a basic approach to implementing Bayesian statistics in Python.

1. Setting Up the Environment

First, you need to install the necessary Python libraries.
The most commonly used libraries for Bayesian statistics in Python are PyMC3, ArviZ, and NumPy.
You can install them using pip:

“`
pip install pymc3 arviz numpy
“`

2. Defining the Model

To illustrate Bayesian estimation, suppose we have a simple coin-flipping experiment.
Let’s say we want to estimate the probability of the coin landing heads-up (denoted as θ).

We start by defining a prior distribution for θ.
Assume a uniform prior, indicating no initial preference:

“`python
import pymc3 as pm

# Define the model
with pm.Model() as model:
theta = pm.Uniform(‘theta’, lower=0, upper=1)
“`

3. Specifying the Likelihood

Next, we incorporate new data, i.e., the result of several coin flips.
Assuming we flipped the coin 10 times and observed 7 heads, we use a binomial likelihood:

“`python
# Likelihood
observations = pm.Binomial(‘obs’, n=10, p=theta, observed=7)
“`

4. Performing Bayesian Inference

To update our prior belief, we perform Bayesian inference using the No-U-Turn Sampler (NUTS):

“`python
# Inference
trace = pm.sample(1000, return_inferencedata=False)
“`

5. Summarizing the Posterior

Finally, we analyze the results to obtain the posterior distribution of θ:

“`python
import arviz as az

# Summarize the trace
az.plot_trace(trace)
az.plot_posterior(trace)
“`

This approach provides us with a posterior distribution that represents updated beliefs about the coin’s probability of heads after observing the data.

Benefits of Bayesian Statistics

Bayesian statistics offers numerous benefits compared to classical statistical methods:

1. Incorporation of Prior Knowledge

Bayesian methods allow for the integration of prior knowledge or expert opinion into the analysis.
This flexibility is useful when data is sparse or previous research provides valuable insights.

2. Probabilistic Interpretation

Bayesian statistics provides probabilistic interpretations of parameters, allowing for meaningful uncertainty estimates.
This is particularly beneficial in fields where decision-making under uncertainty is crucial.

3. Model Comparison and Selection

Bayesian framework supports rigorous model comparison and selection, even with complex models.
This capability is important when dealing with multiple competing hypotheses or models.

Conclusion

Bayesian statistics is a powerful tool with a wide range of applications across various fields.
Its ability to update prior beliefs with new evidence makes it an invaluable approach for complex decision-making processes.
With tools like Python libraries PyMC3 and ArviZ, implementing Bayesian estimation has become more accessible to researchers and practitioners.

As data continues to grow in importance, understanding and applying Bayesian statistics will be a valuable skill for analyzing and interpreting data in a meaningful way.
Whether you’re in academia, industry, or a data-related profession, embracing Bayesian methods can enhance your work and lead to more informed conclusions.

WHITE PAPER

この記事の理解を深める
無料ホワイトペーパーをプレゼント

製造業の現場で使える実務資料(PDF)を無料でお届けします。"こんな資料が届きます" ↓ 下のボタンからどうぞ。

FREE DOCUMENT — サービス資料(PDF・無料)

製造業の見積・受発注クラウド
「Newji one」とは

Newji one は、製造業の調達・受発注に特化したクラウド/AIエージェント。見積依頼・発注書作成・進捗管理・承認をひとつの画面に集約し、AIが比較と異常検知を担当。最後の「GO」だけ人が押す仕組みです。

  • 見積〜発注〜納期を一元管理。催促・転記のムダをゼロに
  • AIが相見積もり比較と異常検知。あなたは判断だけに集中
  • 取引先は「招待」で完全無料。自社コストだけで取引先ごとデジタル化

※ 取引先から招待された企業様は完全無料でご利用いただけます

NEWJI総研

購買・調達や設計・品質の実務を、
研修テキストと実務書式にまとめています。
無料サンプルで中身を確かめられます。

NEWJI総研の資料を見る

OEM/ODM 生産委託

アイデアはある。作れる工場が見つからない。
試作1個から量産まで、加工条件に合わせて最適提案します。
短納期・高精度案件もご相談ください。

加工可否を相談する

AI/DX支援

見積・発注、紙・FAX、品質記録など、
人に頼って回っている業務を、AIと仕組みで回る形に。
まずは無料でご相談ください。

AI/DX支援を見る

見積・発注クラウド Newji one

受発注が増えるほど、入力・確認・催促が重くなる。
受発注管理を“仕組み化“して、ミスと工数を削減しませんか。
見積・発注・納期まで一元管理できます。

機能を確認する

You cannot copy content of this page