3

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()

2 Answers 2

2

That's generally right, once you fix the name errors (I assume logods and data are meant to be the same). 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. But that doesn't affect the correctness of the code, just the understandability.

Sign up to request clarification or add additional context in comments.

Comments

0

I would use OpenTURNS's UniformFactory: the build method returns a distribution which has a drawPDF method.

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:

Uniform distribution

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.