0

我有一个直方图,它代表我网络的度数分布。我需要将它拟合到二项式分布,但由于 Scipy 中没有离散分布的 .fit 方法,我不知道如何获取二项式函数所需的参数。

似乎我没有从直方图中得到正确的参数,因为二项式图与直方图的形状不匹配。我究竟做错了什么?

G = nx.gnm_random_graph(5,5)# My Graph

d=np.array(list(dict(nx.degree(G,weight='weight')).values()))#Calculating 
degree distribution
c = np.array(range(0,len(d),1))# The number of nodes

h = plt.hist(d,density= True ,bins=25, stacked = True)#histogram

bionom_func= st.binom.pmf(k,n,p)# defining the binomial function


popt, pcov = optimize.curve_fit(f=bionom_func, xdata=c, ydata=d)

estimated_n = popt[0]
estimated_p = popt[1]
modeled_y = st.binom.pmf(c, estimated_n, estimated_p)
plt.plot(c, modeled_y, 'r-')# plotting the fit curve


plt.show()
4

0 回答 0