小编M N*_*lle的帖子

scipy curve_fit 引发“OptimizeWarning:无法估计参数的协方差”

我正在尝试将此函数拟合到一些数据中:

在此处输入图片说明

但是当我使用我的代码时

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

def f(x, start, end):
    res = np.empty_like(x)
    res[x < start] =-1
    res[x > end] = 1
    linear = np.all([[start <= x], [x <= end]], axis=0)[0]
    res[linear] = np.linspace(-1., 1., num=np.sum(linear))
    return res

if __name__ == '__main__':

    xdata = np.linspace(0., 1000., 1000)
    ydata = -np.ones(1000)
    ydata[500:1000] = 1.
    ydata = ydata + np.random.normal(0., 0.25, len(ydata))

    popt, pcov = curve_fit(f, xdata, ydata, p0=[495., 505.])
    print(popt, pcov)
    plt.figure()
    plt.plot(xdata, …
Run Code Online (Sandbox Code Playgroud)

python curve-fitting scipy lmfit

6
推荐指数
1
解决办法
2万
查看次数

标签 统计

curve-fitting ×1

lmfit ×1

python ×1

scipy ×1