我在使用scipy Optimize软件包使曲线拟合时有些麻烦。我的代码是:
import numpy as np
import matplotlib.pyplot as plt
from scipy.optimize import curve_fit
def drm(x,y,func, mprint = False):
x = np.array(x)
y = np.array(y)
# flip array values
x = x[::-1] - np.amin(x)
y = y[::-1]
popt, pcov = curve_fit(func, x, y)
if mprint:
plt.figure()
plt.plot(x, y, 'ko', label="Original Data")
plt.plot(x, func(x, *popt), 'r-', label="Fitted Curve")
plt.legend()
plt.show()
return popt
# 1. Function for Weibull (type 1) with lower limit at 0
def W1_3(x, b, d, e):
Function_W1_3(x, b, 0, d, e)
def Function_W1_3(x, b, c, d, e):
if e == 0:
e = 1e-8
return c + (d-c) * np.exp(-np.exp(b * (np.log(x) - np.log(e))))
y= [207, 263, 401, 460, 531, 576, 1350, 2317, 2340, 2834]
x= [135, 126, 120, 100, 90, 85, 80, 70, 65, 60]
popt = drm(x, y, W1_3, mprint = True)
print(popt)
我犯了一个典型错误,但我不明白自己在做什么错... TypeError:-:“ NoneType”和“ float”的不受支持的操作数类型
有人可以帮我吗?
非常感谢!
Xevi