У меня возникли проблемы с подбором кривой с помощью пакета 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
# 3. Function for Log-logistic (ED50 as parameter) with lower limit at 0
def LL3(x, b, d, e):
return Function_LL_3(x, b, 0, d, e, 1)
def LL4(x, b, c, d, e):
return Function_LL_3(x, b, c, d, e, 1)
def Function_LL_3(x, b, c, d, e, f):
#x[x==0] = 1e-8
if e==0:
e = 1e-7
return c + ((d - c)/((1 + np.exp(b * (np.log(x) - np.log(e)))) ** f))
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, LL4, mprint = True)
print(popt)
Я получаю очень плохую кривую ... Так что наверняка оптимизация не выполнена хорошо. Я также получаю это предупреждение RuntimeWarning: деление на ноль, встречающееся в журнале
Может ли кто-нибудь помочь мне с этим, пожалуйста?
Большое спасибо!
Xevi