【发布时间】:2018-08-16 12:08:45
【问题描述】:
我正在尝试将我的数据拟合到 4 个参数物流,我得到了这样的图表:
我认为第 4~10 个数据点的曲线看起来不错,但我不明白第 1~3 个数据点发生了什么。我也收到了错误信息
“RuntimeWarning: power return 遇到无效值 ((A-D)/(1.0+((x/C)**B))) + D”。
用于制作图表的代码如下:
import numpy as np
import matplotlib.pyplot as plt
from scipy import stats
import scipy.optimize as optimization
xdata = np.array([0.00001, 0.000033, 0.0001, 0.00033,
0.001, 0.0033, 0.01, 0.033, 0.1, 0.33])
ydata = np.array([591, 648.5, 714.75, 941, 1226, 1768.25,
2232.25, 2716.25, 3056.25, 3034.5])
ydata2 = np.array([595.5, 711, 898.25, 2215.5,
2791.25, 3115.5, 3351, 3301, 3456.25, 3171.5])
ydata3 = np.array([617, 597.5, 599.25, 680, 683.5, 1152.75, 1554.25,
2221.5, 2821.5, 2719.25])
def fourPL(x, A, B, C, D):
return ((A-D)/(1.0+((x/C)**B))) + D
params, params_covariance = optimization.curve_fit(fourPL, xdata,
ydata)
x_min, x_max = np.amin(xdata), np.amax(xdata)
xs = np.linspace(x_min, x_max, 1000)
plt.scatter(xdata, ydata)
plt.plot(xs, fourPL(xs, *params))
plt.semilogx()
plt.show()
供您参考
- 当我只使用 7 个数据点时,曲线拟合得很好。
- 当我从一开始就以日志形式使用
xdata并添加 6 以使数字为正数(xdata_log = np.log10(xdata)+6)时,它在 10 个数据点上运行良好。
我不明白发生了什么。
任何建议或 cmets 将不胜感激。
提前致谢。
【问题讨论】:
标签: python optimization scipy curve-fitting