简体   繁体   English

为什么 python 中的 scipy.optimze 中的 curve_Fit 在这段代码中表现得很奇怪?

[英]Why curve_Fit from scipy.optimze in python acting weird in this code?

I've got this weird problem with a very simple piece of code.我用一段非常简单的代码遇到了这个奇怪的问题。 I've looked at countless examples and they all seem to work fine, but for some reason mine doesn't…我看过无数的例子,它们似乎都运行良好,但出于某种原因,我的不......

What I'm trying to achieve, is to set the point at which the plotting of the regression model begins.我想要实现的是设置回归模型绘图开始的点。 I want it to be, say 5000, instead of zero.我希望它是,比如说 5000,而不是零。 At the opposite end it works fine Ie if I set the regression to end at a desired point, it will, but starting at any other point besides zero doesn't work.在另一端它工作正常,即如果我将回归设置为在所需的点结束,它会,但从零以外的任何其他点开始都不起作用。 If I set “start” xFit1 to be a non-zero value, the scaling goes all weird, while the beginning of the plot just remains at zero.如果我将“start”xFit1 设置为非零值,缩放会变得很奇怪,而绘图的开头只是保持为零。 What might be going on, any ideas?可能发生了什么,有什么想法吗?

AVG_PNTSx = []
u = 0
p = 0
S_O = False

#Array creation

#Add each sample preparation result here manually:  
AVG_PNTSy = [14, 30, 64, 130, 300, 400, 1220, 2660, 4939, 10100, 10600, 10900, 10000, 22150, 45000]

#Auto creation of x-array based on y-array
for i in range(len(AVG_PNTSy)):
    u = (i*20001)+10000
    AVG_PNTSx.append(u)

#Exp Regression

def func(x,a,b):
    return a*np.exp(b*x)

xFit1 = np.arange(start,300000,1)

init_guess = [1,0.00001]

popt, pcov = curve_fit(func, AVG_PNTSx, AVG_PNTSy,init_guess)

#Plots
p3, = plt.plot((func(xFit1,*popt)))
plt.plot(AVG_PNTSx,AVG_PNTSy,"ro")  

Thanks in advance!提前致谢!

When you do the plotting you are forgetting to put the X.当您进行绘图时,您会忘记放置 X。

A solution:一个办法:

xFit2=np.arange(50000, 300000, 1)

#Plots
p3, = plt.plot(xFit2,(func(xFit2,*popt)))
plt.plot(AVG_PNTSx,AVG_PNTSy,"ro")

在此处输入图片说明

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

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