我想要符合以下数据:

x(time) y(data)    
0.75;   19.33    
1;      19.04   
1.25;   17.21   
1.5;    12.98   
1.75;   11.59   
2;  9.26   
2.25;   7.66   
2.5;    6.59    
2.75;   5.68    
3;  5.1    
3.25;   4.36   
3.5;    4.43     
3.75;   3.58    
4;  3.01    
4.25;   3.24     
4.5;    3.58     
4.75;   3.13     
5;  3.88     
5.25;   3.19     
5.5;    3.58     
5.75;   3.64

使用以下代码:

#read text file
data = pd.read_table('episode_5_prova.txt', sep='\t')
#DataFrame
df = pd.DataFrame(data)
#Define your function
def func(x, a, b, c, d, e):
return a*np.exp(-b*x) + c*np.exp(-d*x) + e

#convert dataframe into numpy array
df0=df['time']
x=df0.as_matrix()
df1=df['bi']
y=df1.as_matrix()

# Using the python scipy function curve_fit with function and input variables
popt, pcov = curve_fit(func, x, y)
a, b, c, d, e= popt
fit = func(x, a, b, c, d, e)

fig, ax = plt.subplots()
ax.plot(x, fit, color='r', lw=3)
ax.plot(x, y,'g.')
observed_values=scipy.array(y)
expected_values=scipy.array(fit)
plt.xlim(0,25)
plt.ylim(0,20)

print(a,b,c,d,e)

print(scipy.stats.chisquare(observed_values, f_exp=expected_values, ddof=3))
plt.show()

我获得了以下情节:first fit但是,出于我的工作目的,我需要将我的参数b和c修复为:b = 0.000431062,d = 0.000580525但是我没有得到如下拟合:second fit

有没有人有建议?谢谢