시작하기무료로 시작하기

결과 확인하기

이제 직접 표본을 생성하고 기댓값과 분산을 계산한 뒤, binom에서 제공하는 메서드를 사용해 표본 값이 이론값과 일치하는지 확인해 보세요.

scipy.statsbinom 객체와 describe() 메서드는 이미 로드되어 있으니 바로 계산할 수 있어요.

이 연습은 강의의 일부입니다

Python으로 배우는 확률 기초

강의 보기

연습 안내

  • sample 변수의 표본 평균과 분산을 계산하세요.
  • n=10, p=0.3을 사용해 기댓값을 계산하고, mean1 - p로 분산을 계산하세요.
  • p=0.3인 동전 10번 던지기에 대해, binom 메서드를 사용해 기댓값과 분산을 구하세요.

실습형 인터랙티브 연습

이 예제를 이 샘플 코드를 완성하여 풀어보세요.

sample = binom.rvs(n=10, p=0.3, size=2000)

# Calculate the sample mean and variance from the sample variable
sample_describe = describe(____)

# Calculate the sample mean using the values of n and p
mean = ____*____

# Calculate the sample variance using the value of 1-p
variance = mean*____

# Calculate the sample mean and variance for 10 coin flips with p=0.3
binom_stats = binom.stats(n=____, p=____)

print(sample_describe.mean, sample_describe.variance, mean, variance, binom_stats)
코드 편집 및 실행