I have a histogram which represents the degree distribution of a network for me. I need to fit it to Binomial distribution, but since there is no .fit method for discrete distributions in Scipy, I don't know how to get the parameters needed for the binomial function.
It seems that I am not getting the correct parameters from the histogram since the binomial plot doesn't match the shape of the histogram. what am I doing wrong?
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()