【问题标题】:Why does the optimize.curve_fit not work on smaller datasets?为什么 optimize.curve_fit 不适用于较小的数据集?
【发布时间】:2020-08-15 08:12:03
【问题描述】:

我对我的数据H2OCO2 执行了分段线性拟合。它适用于 288 数据点的数据集,但不适用于 144 数据点的数据集。我的代码如下:

#Piecewiselinear fit
x = np.array(H2O)
y = np.array(CO2)
p , e = optimize.curve_fit(piecewise_linear, x, y)
xd = np.linspace(0, 1, 1000)

对于144数据点的数据集,唯一的区别发生在运行optimize.curve_fit时。我收到以下消息OptimizeWarning: Covariance of the parameters could not be estimated category=OptimizeWarning。这些是不同的情节: Correct fit (288 points)Incorrect fit (144 points)

出了什么问题?我该如何解决这个问题?

【问题讨论】:

    标签: python numpy statistics linear-regression piecewise


    【解决方案1】:

    我最终改变了常见的方法

    def piecewise_linear(x, x0, y0, k1, k2):
        return np.piecewise(x, [x < x0], [lambda x:k1*x + y0-k1*x0, lambda x:k2*x + y0-k2*x0])
    

    my_pwlf = pwlf.PiecewiseLinFit(x, y)
    breaks = my_pwlf.fit(2) #if you want multiple breakpoints change the number in the bracket.
    print(breaks)
    
    x_hat = np.linspace(x.min(), x.max(), 100)
    y_hat = my_pwlf.predict(x_hat)
    

    因此,我还得到了断点的 x 值。

    【讨论】:

      猜你喜欢
      • 2016-10-12
      • 2021-09-17
      • 2016-01-31
      • 1970-01-01
      • 2021-06-18
      • 2018-10-06
      • 1970-01-01
      • 1970-01-01
      • 2021-04-17
      相关资源
      最近更新 更多