回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>我正在尝试使用scipy.optimize.curve\u fit优化指数拟合。但结果并不好。我的代码是:</p>
<pre><code>def func(x, a, b, c):
return a * np.exp(-b * x) + c
# xdata and data is obtain from another dataframe and their type is nparray
xdata =[36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70 ,71,72]
ydata = [4,4,4,6,6,13,22,22,26,28,38,48,55,65,65,92,112,134,171,210,267,307,353,436,669,669,818,1029,1219,1405,1617,1791,2032,2032,2182,2298,2389]
popt, pcov = curve_fit(func, xdata, ydata)
plt.plot(xdata, func(xdata, *popt), 'r-', label='fit: a=%5.3f, b=%5.3f, c=%5.3f' % tuple(popt))
plt.scatter(xdata, ydata, s=1)
plt.show()
</code></pre>
<p>然后我得到了这样的结果:</p>
<p><a href="https://i.stack.imgur.com/ieCUh.jpg" rel="nofollow noreferrer">enter image description here</a></p>
<p>结果表明:</p>
<pre><code>pcov = [[inf inf inf] [inf inf inf] [inf inf inf]]
popt = [1 1 611.83784]
</code></pre>
<p>我不知道如何使我的曲线拟合得很好。你能帮我吗?谢谢大家!</p>