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). 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With