本文介绍了倾斜的正态分布的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道如何用scipy绘制偏态正态分布吗?
我认为可以使用stats.norm类,但我不知道如何使用。
此外,我如何估算描述一维数据集的偏态正态分布的参数?

Does anyone know how to plot a skew normal distribution with scipy?I supose that stats.norm class can be used but I just can't figure out how.Furthermore, how can I estimate the parameters describing the skew normal distribution of a unidimensional dataset?

推荐答案

来自维基百科,

from scipy import linspace
from scipy import pi,sqrt,exp
from scipy.special import erf

from pylab import plot,show

def pdf(x):
    return 1/sqrt(2*pi) * exp(-x**2/2)

def cdf(x):
    return (1 + erf(x/sqrt(2))) / 2

def skew(x,e=0,w=1,a=0):
    t = (x-e) / w
    return 2 / w * pdf(t) * cdf(a*t)
    # You can of course use the scipy.stats.norm versions
    # return 2 * norm.pdf(t) * norm.cdf(a*t)


n = 2**10

e = 1.0 # location
w = 2.0 # scale

x = linspace(-10,10,n)

for a in range(-3,4):
    p = skew(x,e,w,a)
    plot(x,p)

show()

如果要从数据集中查找比例,位置和形状参数,请使用 scipy.optimize.leastsq ,例如使用 e = 1.0 w = 2.0 a = 1.0

If you want to find the scale, location, and shape parameters from a dataset use scipy.optimize.leastsq, for example using e=1.0,w=2.0 and a=1.0,

fzz = skew(x,e,w,a) + norm.rvs(0,0.04,size=n) # fuzzy data

def optm(l,x):
    return skew(x,l[0],l[1],l[2]) - fzz

print leastsq(optm,[0.5,0.5,0.5],(x,))

应该给你类似的东西,

(array([ 1.05206154,  1.96929465,  0.94590444]), 1)

这篇关于倾斜的正态分布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 10:57