python - 为什么 python 中 scipy.optimze 中的 curve_Fit 在这段代码中表现得很奇怪?
问题描述
我用一段非常简单的代码遇到了这个奇怪的问题。我查看了无数示例,它们似乎都运行良好,但由于某种原因,我的却没有……</p>
我想要实现的是设置回归模型开始绘制的点。我希望它是 5000,而不是零。在另一端它工作正常,即如果我将回归设置为在所需的点结束,它会,但从零以外的任何其他点开始都不起作用。如果我将“start”xFit1 设置为非零值,则缩放会变得很奇怪,而绘图的开头则保持为零。可能会发生什么,有什么想法吗?
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")
提前致谢!
解决方案
推荐阅读
- qt - QGraphicsSvgItem:没有这样的文件或目录
- math - 找到到达给定坐标所需的最小速度?
- flutter - 我正在尝试获取数据并在文本小部件中写入。但是我有一个错误类型'String'不是'int'类型的子类型?我怎样才能解决这个问题?
- laravel - 无法让用户在使用 facebook socialite 登录之前选择帐户
- javascript - 在 Gatsby 和 Material UI 中使用 Lottie 动画时出现布局问题
- scala - Scala遗留代码:如何在执行路径的不同点访问输入参数?
- laravel - Laravel 翻译动态电子邮件(不带翻译文件)
- javascript - JS - 发送电子邮件需要用户登录 gmail 帐户
- python - 使用条件的变量转换不能正常工作,如何调试?
- swift - 钥匙串 API 只查看系统钥匙串而不是登录钥匙串 Mac OS Swift