简体   繁体   English

使用具有预定平均值和标准(位置和比例)的scipy进行拟合分布?

[英]Fit t distribution using scipy with predetermined mean and std(loc & scale)?

How can I fit t distribution using scipy.stats.t.fit() with predetermined mean and std? 如何使用具有预定平均值和标准的scipy.stats.t.fit()来拟合t分布?

The question is, I have a standardized dataset, with mean=0 and std=1 , I only want to get df of t distribution. 问题是,我有一个标准化的数据集, mean=0std=1 ,我只想获得t分布的df But when I do scipy.stats.t.fit(data) , it outputs df, loc, scale , and loc&sclae not necessarily equal to 0&1. 但是当我做scipy.stats.t.fit(data) ,它输出的df, loc, scale和loc&sclae不一定等于0和1。

How can I solve this? 我怎么解决这个问题? Thanks! 谢谢!

In the call to .fit() , use the arguments floc=0 and fscale=1 to fix these parameters. .fit()的调用中,使用参数fscale=1 floc=0fscale=1来修复这些参数。

Here's an example. 这是一个例子。 First, import t and generate a sample to work with: 首先,导入t并生成一个样本以使用:

In [24]: from scipy.stats import t

In [25]: np.random.seed(123)

In [26]: sample = t.rvs(3, loc=0, scale=1, size=10000)

Now use the .fit() method to fit the t distribution to the sample, constraining the location to 0 and the scale to 1: 现在使用.fit()方法将t分布拟合到样本,将位置约束为0,将比例约束为1:

In [27]: t.fit(sample, floc=0, fscale=1)
Out[27]: (3.1099609375000048, 0, 1)

There are more examples (using different distributions) in the fit docstring and here on stackoverflow . fit docstring中有更多的例子(使用不同的发行版),在这里有stackoverflow

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM