Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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()
like image 864
Nilani Algiriyage Avatar asked Feb 25 '26 22:02

Nilani Algiriyage


1 Answers

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.

like image 182
Robert Kern Avatar answered Feb 28 '26 11:02

Robert Kern



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!