기본 콘텐츠로 건너뛰기

라벨이 기하분포인 게시물 표시

[matplotlib]quiver()함수

확률, 통계 관련 그래프

다음 그래프들은 전자책 파이썬과 함께하는 통계이야기 3 장에 수록된 그림들의 코드들입니다. import numpy as np import pandas as pd from scipy import stats import matplotlib.pyplot as plt import seaborn as sns sns.set_style("darkgrid") #fig 311 uni, p=[0, 1, 2],[0.25, 0.5, 0.25] fig, ax=plt.subplots(figsize=(4,3)) ax.bar(uni, p, color="g", alpha=0.3) ax.set_xlabel("# of head(H)") ax.set_ylabel("PMF") ax.set_yticks(p) ax.set_xticks(uni) plt.show() #fig 312 import itertools ca=list(itertools.product(range(1, 7), repeat=2)) S=[sum(i) for i in ca] uni, fre=np.unique(S, return_counts=True) fresum=sum(fre) p=[i/fresum for i in fre] fig, ax=plt.subplots(figsize=(4,3)) ax.bar(uni, p, color="g", alpha=0.3) ax.set_xlabel("Sum of number") ax.set_ylabel("PMF") ax.set_yticks(np.array(p).round(3)) ax.set_xticks(uni) plt.show() #fig 313 ca=list(itertools.product([0, 1], repeat=2)) S=[sum(i) for i in ca] uni, fre=np.unique(S, return_counts=True) re=pd.DataFrame([...

[data analysis] 기하분포(Geometric distribution)

기하분포(Geometric distribution) 결과가 성공과 실패인 베르누이 시행 을 반복하여 첫번째로 성공이 나올때까지의 확률변화의 분포를 기하분포 (Geometric distribution) 라고 합니다. 예를 들어 성공확률이 p인 베르누이 시행을 반복시행하여 최초 성공(s)이 되는 경우를 확률변수 X로 하는 확률질량함수는 식 1과 같이 될 것입니다. S x = {1, 2, · · · } (식 1) f(1) = P(X = 1) = p f(2) = P(X = 2) = (1 − p)p ⋮ 위의 결과를 일반화하면 기하분포의 확률질량함수는 식 2와 같이 공식화 할 수 있습니다. f(x) = P(X = x) = (1 − p) x−1 p (식 2) 식 2와 같이 확률질량함수는 매개변수 p에만 의존하므로 기하분포는 식 3으로 표시하며 유일한 매개변수에 의한 기하분포의 변화는 그림 1에서 확인할 수 있습니다. X ∼ Geometric(p) (식 3) 그림 1 모수에 따른 기하분포의 변화. fig, ax=plt.subplots(figsize=(4,3)) p=[p1,p2,p3,p4] col=['g','b','r','k'] nme=[0.1, 0.3, 0.5, 0.7] for i in range(len(p)): ax.plot(x, p[i], color=col[i], label=f"Geometric({nme[i]})") ax.set_xlabel("x") ax.set_ylabel("Probability") ax.legend(loc="best") plt.show() X ∼ Geometric(p) 분포의 기대값과 분산을 모멘트생성함수(MGF)로부터 유도해 봅니다. 식 4는 기하분포의 MGF 입니다. \begin{align}M_x(t)&=E(e^{tX})\\ &=\sum^\infty_...