【问题标题】:Curve fit error: "Covariance of the parameters could not be estimated" to logistic model曲线拟合错误:“无法估计参数的协方差”到逻辑模型
【发布时间】:2022-06-10 18:46:44
【问题描述】:

我正在尝试使用curve_fit 将以下数据拟合到逻辑函数,如下所示。我的代码很简单:

X=[0,15,30,45,60,75,90,105,120,135,150,165,180]
Y=[0.037812, 0.037735, 0.037721, 0.037634, 0.037373, 0.037173, 0.036373, 0.035833, 0.035741, 0.035727, 0.035668, 0.035674, 0.035652]

def logistic(x,a,b,c,d):
    return a / (1.0 + np.exp(-c * (x - d))) + b

popt, pcov = fit(logistic, X, Y)

plt.plot(X,Y, 'o',label='Data')
lin=np.linspace(0,180,1000)
plt.plot(lin,logistic(lin,*pop), '--')

但是当我运行它时,我得到了这个错误:

OptimizeWarning:无法估计参数的协方差

并且绘制的曲线看起来不像它应该的那样。谁能明白为什么 Python 不能将我的数据拟合到逻辑曲线?

【问题讨论】:

  • 您定义了 X 和 Y,但您正在绘制 X 和 T,也许这可以解释为什么它们看起来不一样。如果您发布完整的示例,它会有所帮助。
  • 这只是抄写代码时的拼写错误,虽然我正在绘制 X,Y

标签: python logistic-regression curve-fitting


猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-10-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-05-23
相关资源
最近更新 更多