简体   繁体   English

最佳拟合线与散点图不匹配

[英]The line of best fit doesn't match the scatter plot

Below is my scatter plot with a regression linear.下面是我的带有回归线性的散点图。 Just by looking at how the markers are distributed on the plot, I feel like the linear is not covering them correctly.仅通过查看标记在绘图上的分布方式,我觉得线性没有正确覆盖它们。 From what i see, it is supposed to be more of a diagonal and a more straight line instead of a curve.从我看来,它应该更像是一条对角线和一条更直线,而不是一条曲线。 here is my code producing the plot:这是我生成情节的代码:

for i in range (len(linkKarmaList)):
    plt.scatter(commentKarmaList[i], linkKarmaList[i], marker="o", s=len(clearModSet[i])*1.0*0.9)
x = numpy.asarray(commentKarmaList)
y = numpy.asarray(linkKarmaList )
plt.plot(numpy.unique(x), numpy.poly1d(numpy.polyfit(x, y, 1))(numpy.unique(x)))
plt.xlabel('Comment Karma ')
plt.ylabel('Link Karma')
plt.title('Link and comment Karma of most popular Forums on reddit')
plt.xscale('log')
plt.yscale('log')
plt.legend()
plt.show

Am I interpreting that correctly?我的解释正确吗? What am I missing?我错过了什么?

在此处输入图片说明

You're trying to fit a straight line y = a*x + b , which doesn't look like a straight line in log-space.您正在尝试拟合一条直线y = a*x + b ,它在对数空间中看起来不像直线。 Instead, you should be plotting a straight line in log-space.相反,您应该在对数空间中绘制一条直线。

This comes down to log(y) = a * log(x) + b Which we can then rewrite to log(y) = log(x^a) + b If we then take the exponent of this, we find: y = x^a * 10^b or just y = C * x^a , where C (=10^b) and a are the fitting parameters and x and y are your data.这归结为log(y) = a * log(x) + b然后我们可以将其重写为log(y) = log(x^a) + b如果我们然后取其指数,我们会发现: y = x^a * 10^b或只是y = C * x^a ,其中C (=10^b) 和a是拟合参数, xy是您的数据。 This is the function that makes a straight line in log-log space, which is the function you should try to fit against your data.这是在 log-log 空间中形成一条直线的函数,这是您应该尝试适应数据的函数。

From what you show, I'd say the problem is that in the log-log plot the scatterplot looks more or less like a line.从你展示的内容来看,我想说的问题是,在对数对数图中,散点图看起来或多或少像一条线。

The problem is that you're fitting against natural values and then plotting in a log-log plot.问题是您要针对自然值进行拟合,然后在对数对数图中进行绘制。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM