个性化阅读
专注于IT技术分析

Python统计中的68-95-99.7规则

经验法则(也称为68-95-99.7规则或者三西格玛规则)指出正态分布, 我们有以下观察结果:

68%的观测值在平均值附近的1个标准偏差之间:

(\ mu- \ sigma)\到\(\ mu + \ sigma)

95%的观测值位于平均值附近的两个标准偏差之间:

(\ mu-2 \ sigma)\到\(\ mu + 2 \ sigma)

99.7%的观测值在平均值附近的3个标准差之间:

(\ mu-3 \ sigma)\到\(\ mu + 3 \ sigma)

以下是一个标准正态分布图, 其中(平均值=0和标准偏差=1), 说明经验法则。

Python –统计中的68-95-99.7规则1

我们可以使用Python的科学模块。

我们可以使用cdf()的功能scipy.stats.norm计算累积概率(分布曲线下的面积)的模块。

语法:cdf(x, 平均值, SD)参数:x:累积概率将要计算到的值平均值:分布的平均值SD:分布的标准偏差

Python –统计中的68-95-99.7规则2

下面是实现:

import matplotlib.pyplot as plt
import numpy as np
from scipy.stats import norm
  
# setting the values of
# mean and S.D.
mean = 0
SD = 1
  
# value of cdf between one, two
# and three S.D. around the mean
one_sd = norm.cdf(SD, mean, SD) - norm.cdf( - SD, mean, SD)
two_sd = norm.cdf( 2 * SD, mean, SD) - norm.cdf( - 2 * SD, mean, SD)
three_sd = norm.cdf( 3 * SD, mean, SD) - norm.cdf( - 3 * SD, mean, SD)
  
# printing the value of fractions
# within each band
print ( "Fracton of values within one SD =" , one_sd)
print ( "Fracton of values within two SD =" , two_sd)
print ( "Fracton of values within three SD =" , three_sd)

输出:

Fracton of values within one SD = 0.6826894921370859
Fracton of values within two SD = 0.9544997361036416
Fracton of values within three SD = 0.9973002039367398

因此, 我们看到值的分数几乎等于0.65, 0.95和0.997。因此, 验证了经验法则。

首先, 你的面试准备可通过以下方式增强你的数据结构概念:Python DS课程。


赞(1)
未经允许不得转载:srcmini » Python统计中的68-95-99.7规则

评论 抢沙发

评论前必须登录!