Not sure what distribution to use to model my data

ぐ巨炮叔叔 提交于 2020-01-04 09:08:07

问题


I have a set of astronomical data, to which I'm trying to fit a curve:

My fitting code is

param = stats.norm.fit(df['delta z'].dropna())   # Fit a normal distribution to the data
pdf_fitted = stats.norm.pdf(df['delta z'], *param)
x = np.linspace(*df['delta z'].agg([min, max]), 1000) # x-values
binwidth = np.diff(edges).mean()
ax.plot(x, stats.norm.pdf(x, *param)*h.sum()*binwidth, color = 'r')

which produces

Now, I'm clearly doing this in the wrong way, because the curve doesn't fit the data at all. All of the tutorials I've seen, such as here involve making a set of data, in which case we already know things like the mean and the skew. This question led me to estimate the parameters with

a_estimate, loc_estimate, scale_estimate = stats.skewnorm.fit(df['delta z'])
ax.plot(x, skewnorm.pdf(x, a_estimate, loc_estimate, scale_estimate), 'r-', lw=5, alpha=0.6, label='skewnorm pdf')

which produces

so how can I plot the fit with those parameters?


回答1:


In the comments you state that you don't know how to plot the curve: here is a small example fitting and plotting skewnorm.

import numpy as np
import scipy.stats as ss
import matplotlib.pyplot as plt

data = ss. expon.rvs(size=1000)

P = ss.expon.fit(data)
rX = np.linspace(min(data), max(data), 50)
rP = ss.skewnorm.pdf(rX, *P)

plt.hist(data,bins=25, normed=True, color='slategrey')

plt.plot(rX, rP, color='darkturquoise')
plt.show()


来源:https://stackoverflow.com/questions/56961468/not-sure-what-distribution-to-use-to-model-my-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!