Statistics ( scipy.stats)
TOC \o 1-3 \h \z \u Statistics (scipy.stats) 1
介绍 1
随机变量 2
取得帮助 2
通用方法 4
位移和缩放 6
形态参数 8
冻结分布 9
广播 10
离散分布特殊之处 11
分布拟合 13
性能问题和注意事项 13
遗留问题 13
结构具体分布 14
创建一个连续分布,继承rv_continuous类 14
继承rv_discrete类 16
样本分析 21
描述统计 21
T检验和KS检验 23
分布尾部 25
正态分布特殊检验 28
比较两个样本 29
均值 30
对于两个不一样样本进行KS检验 30
核密度估量 31
单元估量 31
多元估量 40
介绍
在这个教程我们讨论一部分scipy.stats模块特征。这里我们意图是提供给使用者一个相关这个包实用性知识。我们推荐reference manual来介绍更多细节。
注意:这个文档还在发展中。
随机变量
有部分通用概率分布类被封装在continuous random variables和discrete random variables中。有80多个连续性随机变量(RVs)和10余个离散随机变量已经用这些类建立。一样,新程序和分布能够被用户新建(假如你结构了一个,请提供它给我们帮助发展这个包)。
全部统计函数被放在子包scipy.stats中,且有这些函数一个几乎完整列表能够使用info(stats)取得。这个列表里随机变量也能够从stats子包docstring中取得介绍。
在接下来讨论中,我们着重于连续性随机变量(RVs)。几乎全部离散变量也符合下面讨论,不过我们也要指出部分区分在“离散分布特殊之处”中。
取得帮助
全部分布能够使用help函数得到解释。为取得这些信息只需要使用像这么简单调用:
from scipy import stats
from scipy.stats import norm
print norm.__doc__
作为例子,我们用这种方法找分布上下界
print bounds of distribution lower: %s, upper: %s % (norm.a,norm.b)
bounds of distribution lower: -inf, upper: inf
我们能够经过调用dir(norm)来取得相关这个(正态)分布全部方法和属性。应该看到,部分方法是私有方法尽管其并没有以名称表示出来(比如它们前面没有以下划线开头),比如veccdf就只用于内部计算(试图使用那些方法将引发警告,因为它们可能会在后续开发中被移除)
为了取得真正关键方法,我们列举冻结分布方法(我们将在下文解释何谓“冻结分布”)
rv = norm()
dir(rv) # reformatted
[__class__, __delattr__, __dict__, __doc__, __getattribute__,
__hash__, __init__, __module__, __new__, __reduce__, __reduce_ex__,
__repr__, __setattr__, __str__, __weakref__, args, cdf, dist,
entropy, isf, kwds, moment, pdf, pmf, ppf, rvs, sf, stats]
最终,我们能经过内省取得全部可用分布信息。
import warnings
warnings.simplefilter(ignore, DeprecationWarning)
dist_continu = [d for d in dir(stats) if
... isinstance(getattr(stats,d), stats.rv_continuous)]
dist_discrete = [d for d in dir(stats) if
... isinstance(getattr(stats,d), stats.rv_discrete)]
print number of continuous distributions:, len(dist_continu)
number of continuous distributions: 84
print number o
原创力文档

文档评论(0)