拟合指数衰减

我正在尝试解决以下线性化方程:

ln⁡{1−y/y}=ln⁡(c)−b(x)

使用python scipy curvefit或其他类似的方法,请你告诉我怎么做?

样本数据:

x = [15, 16, 17, 18, 19, 20]

y = [0.78, 0.67, 0.56, 0.41, 0.31, 0.20]

我到目前为止尝试的代码:

import numpy as np
import scipy as sp
import pylab
from scipy.optimize import curve_fit
import matplotlib.pyplot as plt
import math
import warnings   

def sigmoid(x,c,b):
    y = np.log(c)-b*x
    return y

def sigmoid_solve(y, c, b):
    x = (np.log(c)+np.log((1-y)/y))/b
    return x

y_new = []

x_data = [15, 16, 17, 18, 19, 20]
y_data = [0.78, 0.67, 0.56, 0.41, 0.31, 0.20]


for data in y_data:
    y_new.append(np.log((1-data)/data))


popt, pcov = curve_fit(sigmoid, x_data, y_new)
ce50 = sigmoid_solve(0.5,popt[0],popt[1])

x = np.linspace(10,40,10)
y = 1/(1+np.exp(sigmoid(x, *popt)))
plt.plot(x, y, 'r',label='logistic exp curve fit')
plt.plot(x_data, y_data,'o',label='data plot')
plt.ylim(0, 1)
plt.xlim(10, 50)
plt.legend(loc='best')
plt.savefig('test.png')
plt.close("all")