저는 Joel Grus가 처음부터 Data Science 책을 읽었습니다. 제 질문은 제 6 장에 관한 것이고, 저자는 이항 무작위 변수를 사용하여 정리를 시뮬레이트하고 있습니다.도서 데이터 과학의 중심 극한 정리에 관한 질문은 처음부터
결과는 이항 법의 확률 분포와 정규 분포를 사용한 근사도를 가진 차트가됩니다. 두 플롯은 서로 매우 유사해야합니다. normal_cdf (- 는 [normal_cdf (나는 0.5 뮤 시그마 +) : 그 제공 Author's Chart
코드는 :
import random
from matplotlib import pyplot as plt
from collections import Counter
def bernoulli_trial(p):
return 1 if random.random() < p else 0
def binomial(n, p):
return sum(bernoulli_trial(p) for _ in range(n))
def make_hist(p, n, num_points):
data = [binomial(n, p) for _ in range(num_points)]
histogram = Counter(data)
plt.bar([x-0.4 for x in histogram.keys()],
[v/num_points for v in histogram.values()],
0.8,
color='0.75')
mu = p * n
sigma = math.sqrt(n * p * (1-p))
# use a line chart to show the normal approximation
xs = range(min(data), max(data) + 1)
ys = [normal_cdf(i+0.5, mu, sigma) - normal_cdf(i-0.5, mu, sigma) for i in xs]
plt.plot(xs, ys)
plt.title('Binomial Distribution vs. Normal Approximation')
plt.show()
make_hist(0.75, 100, 10000)
질문은,이 라인의 책과 같은 차트를 도시 i-0.5, mu, sigma) 저자가 +0.5와 -0.5를 사용한 이유는 무엇입니까? 그것에 대한 특별한 이유가 있습니까?
누구든지이 질문에 답하지 못했습니다. 미리 감사드립니다.
normal_cdf은'범위 (-50,50)'의 벡터'X/10.0' 이상이다. 권리? – skrubber
예. 함수는 다음과 같습니다 : def normal_cdf (x, mu = 0, sigma = 1) : return (1 + math.erf ((x-mu) /math.sqrt (2)/sigma))/2. x 축은 다음과 같습니다. xs = [범위 (-50, 50)의 x는 x/10.0]. 왜 10으로 나눕니 까? –
x 축을 따라 -5에서 5 사이의 차트를 축소하는 것만 같습니까? –