아보카도 가격은?

Python으로 배우는 Bayesian 데이터 분석

Michal Oleszak

Machine Learning Engineer

The Avocado, Inc.

아보카도 과일.

Python으로 배우는 Bayesian 데이터 분석

사례 연구: 가격 탄력성 추정

목표: 아보카도 가격 탄력성 추정 및 최적 가격 산출

(가격 탄력성 = 가격 변화가 판매량에 미치는 영향)

  1. 베이지안 회귀 모형 적합.
  2. 모형을 점검해 타당성 확인.
  3. 다양한 가격에 대한 판매량 예측.
  4. 이익 극대화 가격과 그 불확실성 제시.
Python으로 배우는 Bayesian 데이터 분석

아보카도 데이터

print(avocado)
           date  price      volume  type_organic
0    2015-01-04   0.95  313.242777             0
1    2015-01-11   1.01  290.635427             0
2    2015-01-18   1.03  290.434588             0
3    2015-01-25   1.04  284.703108             0
..          ...    ...         ...           ...
334  2018-03-04   1.52   16.344308             1
335  2018-03-11   1.52   16.642349             1
336  2018-03-18   1.54   16.758042             1
337  2018-03-25   1.55   15.599672             1
1 데이터 출처: https://www.kaggle.com/neuromusic/avocado-prices
Python으로 배우는 Bayesian 데이터 분석

pymc3에서 사전분포

formula = "num_bikes ~ temp + work_day + wind_speed"

with pm.Model() as model:

    pm.GLM.from_formula(formula, data=bikes)
    trace = pm.sample(draws=1000, tune=500)
Python으로 배우는 Bayesian 데이터 분석

pymc3에서 사전분포

formula = "num_bikes ~ temp + work_day + wind_speed"

with pm.Model() as model:
    priors = {"wind_speed": pm.Normal.dist(mu=-5)}
    pm.GLM.from_formula(formula, data=bikes, priors=priors)
    trace = pm.sample(draws=1000, tune=500)
Python으로 배우는 Bayesian 데이터 분석

트레이스에서 드로우 추출

temp_draws = trace.get_values("temp")

print(temp_draws)
array([6.8705346, 6.7421152, 6.7393061, ..., 5.966574 , 6.1274128, 6.7149277])
Python으로 배우는 Bayesian 데이터 분석

필요한 것

모형 적합:

  • pm.Model()
  • pm.GLM.from_formula()
  • pm.sample()
  • pm.Normal()

시각화:

  • pm.forestplot()
  • pm.traceplot()

 

예측:

  • pm.fast_sample_posterior_predictive()

 

추론:

  • az.hdi()
Python으로 배우는 Bayesian 데이터 분석

배운 내용을 실습해 봅시다!

Python으로 배우는 Bayesian 데이터 분석

Preparing Video For Download...