You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Scipy进行4-参数Logistic(4PL)曲线拟合的问题求助

4PL曲线拟合问题:低浓度拟合效果差与log转换后拟合异常

问题说明

  • 使用Scipy对科学实验数据做4-参数Logistic(4PL)曲线拟合,目标是匹配常用软件的拟合效果,但低浓度部分拟合效果不佳
  • 尝试对x值做log10转换后拟合,结果只得到直线而非曲线

实验数据与当前代码

import numpy as np
import matplotlib.pyplot as plt
import scipy.optimize as opt
from scipy.optimize import curve_fit

# 浓度数据
conc = np.array([300000, 70376.8, 16509.6, 3873.0, 908.6, 213.1, 50.0, 11.7])
# 响应值数据
ref = np.array([7.11469e+05, 2.16006e+05, 5.81840e+04, 1.39850e+04,
                3.21300e+03, 8.76000e+02, 2.54000e+02, 1.16000e+02])

# 4PL曲线方程
def func(xdata, a, b, c, d): 
    return ((a-d)/(1.0+((xdata/c)**b))) + d

# 计算权重:1/y²
weights = 1 / (ref **2)

# 设置参数边界
amin = 50 
bounds = ([ amin, -np.inf, -np.inf , -np.inf], [np.inf, np.inf, np.inf, np.inf])

# 初始参数猜测
a = min(ref) * 0.9
d = max(ref) * 1.1
b = 1
c = (d-a)/2    
initial_guess = [a, b, c, d] 
print('Initial params:', initial_guess)

# 执行曲线拟合
params, params_covariance = curve_fit(func, conc, ref, p0=initial_guess, method='trf',sigma=weights, bounds=bounds, maxfev=100000)
print('params:', params)

# 生成拟合曲线的坐标点
x_fit = np.arange(min(conc), max(conc), 8) 
y_fit = func(x_fit, *params)

# 绘图
plt.scatter(conc, ref , label='Weighted Data')
plt.plot(x_fit, y_fit, label='Fitted Curve')
plt.xscale('log')
plt.yscale('log')
plt.xlabel('X')
plt.ylabel('Y')
plt.legend()
plt.show()

内容的提问来源于stack exchange,提问作者Marie Thoelke

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.19 02:52:41