幂律拟合曲线不与数据点重叠

问题描述 投票:0回答:1

我一直在尝试使用 Alstott 等人的 powerlaw 包将幂律拟合到我的学位分布数据。以下是我的代码。

import networkx as nx
import powerlaw
import matplotlib.pyplot as plt

g = nx.powerlaw_cluster_graph(1000, 25, 0.9)

degrees = list(dict(g.degree).values())

fit = powerlaw.Fit(degrees, discrete=True)

fig, ax = plt.subplots(figsize = (10,10))

powerlaw.plot_pdf(degrees, color='r', marker = 'o', linestyle='', ax=ax) #plotting binned data points
fit.power_law.plot_pdf(color = 'darkblue', ax=ax) #plotting fitted curve

ax.set_xlabel('k', fontsize = 16)
ax.set_ylabel('P(k)', fontsize = 16)
ax.set_title('Degree Distribution of a Network', fontsize = 20)
ax.tick_params(labelsize = 12)
plt.text(0.05, 0.6, f'γ =  {round(fit.power_law.alpha, 2)}', transform=plt.gca().transAxes, fontsize=20, color='darkblue')
plt.text(0.05, 0.55, '$x_{min}$ = ' + f'{fit.power_law.xmin}', transform=plt.gca().transAxes, fontsize=20, color='darkblue')
plt.text(0.05, 0.50, f'KS Distance: {round(fit.power_law.D, 2)}', transform=plt.gca().transAxes, fontsize=20, color='darkblue')

As you see, the blue fitted curve is distant from the red binned data points. 如您所见,蓝色拟合曲线远离红色分箱数据点。

让我摸不着头脑的是拟合曲线是如何远离所有点的。为什么会这样呢?这是否意味着拟合不可信?科尔莫哥洛夫-斯米尔诺夫距离也很小。 fit.noise_flag 为 false 表示拟合无效。那么,什么给出了?

python networkx curve-fitting mle power-law
1个回答
0
投票

我也遇到同样的问题,请问你找到解决方法了吗?

© www.soinside.com 2019 - 2024. All rights reserved.