확률분포 선택

Python으로 배우는 Monte Carlo 시뮬레이션

Izzy Weber

Curriculum Manager, DataCamp

최대우도추정(MLE)

  • 적합도를 측정해 분포를 선택할 때 사용
    • 데이터에 대한 가능도 최대인 분포가 최적
  • SciPy의 .nnlf()로 음의 가능도 함수 계산
  • .nnlf()로 계산한 MLE 값이 낮을수록 적합도가 좋음
Python으로 배우는 Monte Carlo 시뮬레이션

age 변수의 분포 선택

sns.histplot(dia["age"])

당뇨병 데이터셋의 age 변수 분포 히스토그램

Python으로 배우는 Monte Carlo 시뮬레이션

후보 분포

distributions = [st.laplace, st.norm, st.expon]

라플라스 분포의 PDF

Python으로 배우는 Monte Carlo 시뮬레이션

후보 분포 간 선택

mles = []


for distribution in distributions: pars = distribution.fit(dia["age"])
mle = distribution.nnlf(pars, dia["age"])
mles.append(mle)
print(mles)
[1797.8467779878652, 1764.0693689033028, 1938.171599681118]
Python으로 배우는 Monte Carlo 시뮬레이션

후보 분포 간 선택

for var in ["age", "bmi", "bp", "tc", "ldl", "hdl", "tch", "ltg", "glu"]:

distributions = [st.laplace, st.norm, st.expon] mles = []
for distribution in distributions: pars = distribution.fit(dia[var]) mle = distribution.nnlf(pars, dia[var]) mles.append(mle)
best_fit = sorted(zip(distributions, mles), key=lambda d: d[1])[0] print(f"Best fit reached using {best_fit[0].name}, \ MLE value: {best_fit[1]}, for variable {var}")
Python으로 배우는 Monte Carlo 시뮬레이션

평가 결과

Best fit reached using norm, MLE value: 1764.0693689033028, for variable age
Best fit reached using norm, MLE value: 1283.356127017369, for variable bmi
Best fit reached using norm, MLE value: 1787.7746251622739, for variable bp
Best fit reached using norm, MLE value: 2193.1564373753627, for variable to
Best fit reached using norm, MLE value: 2136.0440476305284, for variable ldl
Best fit reached using norm, MLE value: 1758.1350738323013, for variable hdl
Best fit reached using norm, MLE value: 739.3762494786798, for variable tch
Best fit reached using norm, MLE value: 339.6620870566908, for variable ltg
Best fit reached using norm, MLE value: 1706.0467588930867, for variable glu
Python으로 배우는 Monte Carlo 시뮬레이션

Vamos praticar!

Python으로 배우는 Monte Carlo 시뮬레이션

Preparing Video For Download...