简体   繁体   English

Python拟合均匀分布

[英]Python fit uniform distribution

I'm trying to fit a set of data with uniform distribution.我正在尝试拟合一组均匀分布的数据。 This is what I have tried based on normal distribution fitting.这是我基于正态分布拟合所尝试的。 I'm not sure whether this implementation is correct or not?我不确定这个实现是否正确? Can you please advise.你能给些建议么。

import matplotlib.pyplot as plt
from scipy.stats import uniform
mu, std = uniform.fit(data)


plt.hist(data, normed=True, alpha=0.6, color='#6495ED')


xmin, xmax = plt.xlim()
x = np.linspace(xmin, xmax, 100)
p = uniform.pdf(x, mu, std)
plt.plot(x, p, 'k', linewidth=2)
title = "Fit results: mu = %.2f,  std = %.2f" % (mu, std)
plt.title("Uniform Fitting")
plt.show()

That's generally right, once you fix the name errors (I assume logods and data are meant to be the same).这通常是正确的,一旦您修复了名称错误(我假设logodsdata应该是相同的)。 Note that the parameters of the uniform distribution are general location and scale parameters (specifically, the lower boundary and width, respectively) and should not be named mu and std , which are specific to the normal distribution.请注意, uniform分布的参数是一般位置和尺度参数(具体来说,分别是下边界和宽度),不应命名为mustd ,它们是正态分布特有的。 But that doesn't affect the correctness of the code, just the understandability.但这并不影响代码的正确性,只影响可理解性。

I would use OpenTURNS's UniformFactory : the build method returns a distribution which has a drawPDF method.我会使用 OpenTURNS 的UniformFactorybuild方法返回一个具有drawPDF方法的分布。

import openturns as ot
data = [1.,2.,3.,4.,5.,6., 7., 8.]
sample = ot.Sample(data,1)
distribution = ot.UniformFactory().build(sample)
distribution.drawPDF()

This produces:这产生:

均匀分布

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

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