开始使用免费开始使用

测量一个样本

让我们用一组抛硬币的样本来计算一些概率。您将计算绝对频数和相对频数,并根据样本数据的分布检查理论值。

数组 sample_of_two_coin_flips 包含 1,000 次实验,每次实验由两次公平抛硬币组成。对每次实验,我们记录两次抛掷中正面朝上的次数:0、1 或 2。

我们已为您预加载了 scipy.stats 库中的 binom 对象,以及 find_repeats()relfreq() 方法。您需要用它们来计算本练习中的概率。

本练习是课程的一部分

Python 概率基础

查看课程

交互式实操练习

通过完成这段示例代码来试试这个练习。

# Count how many times you got 2 heads from the sample data
count_2_heads = ____(sample_of_two_coin_flips).counts[2]

# Divide the number of heads by the total number of draws
prob_2_heads = count_2_heads / ____

# Display the result
print(prob_2_heads)
编辑并运行代码