我正在使用scipy.stats.beta来生成Beta分布概率密度函数.

You can see the expected result for the standard interval of [0,1] here: enter image description here

I would like to create the distribution on the interval [-1,1] instead. For a,b = 0.5, 0.5 one would expect the "u" shaped curve to distribute with the mean at 0 and ending at [-1,1]. However, with std = 1 and mean = 0 I get the following: enter image description here

Now, if I set mean = -1 and std = 2 then I get close to what the desired result is: enter image description here

为什么PDF不能使用标准偏差和平均输入按预期进行zoom /居中?我一定不理解分配函数的控制.

from scipy.stats import beta
import matplotlib.pyplot as plt

fig,ax = plt.subplots(nrows=1, ncols=1)

#x = np.linspace(beta.ppf(0.01, a, b),beta.ppf(0.99, a, b), 100)
x = np.arange(-1.0,1.0,0.01)

a, b = 0.5,0.5 #2.31, 0.627
mean = -1
std = 2
#mean, var, skew, kurt = beta.stats(a, b, moments='mvsk')
pdf = beta.pdf(x, a, b, loc=mean, scale=std)

ax.plot(x, pdf,'r-', lw=5, alpha=0.6, label='beta pdf')

mean = np.nanmean(pdf[np.isfinite(pdf)]) 
std = np.nanstd(pdf[np.isfinite(pdf)])

推荐答案

参数locscale是分布的平均值和标准差not.它们是平移和zoom 参数;例如,参见"Location-scale family".对于贝塔分布,loc是支持区间的左端,scale是其长度.

Python相关问答推荐

难以在Manim中正确定位对象

删除任何仅包含字符(或不包含其他数字值的邮政编码)的观察

沿着数组中的轴计算真实条目

_repr_html_实现自定义__getattr_时未显示

更改键盘按钮进入'

如何获取TFIDF Transformer中的值?

如何在solve()之后获得症状上的等式的值

为什么NumPy的向量化计算在将向量存储为类属性时较慢?'

如何在Python中找到线性依赖mod 2

为什么np. exp(1000)给出溢出警告,而np. exp(—100000)没有给出下溢警告?

手动设置seborn/matplotlib散点图连续变量图例中显示的值

Python—为什么我的代码返回一个TypeError

通过追加列表以极向聚合

如何在FastAPI中替换Pydantic的constr,以便在BaseModel之外使用?'

Django Table—如果项目是唯一的,则单行

Django在一个不是ForeignKey的字段上加入'

如果不使用. to_list()[0],我如何从一个pandas DataFrame中获取一个值?

如何在Python中解析特定的文本,这些文本包含了同一行中的所有内容,

Pandas 删除只有一种类型的值的行,重复或不重复

合并Pandas中的数据帧,但处理不存在的列