Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/google-chrome/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x Python pwlf(分段线性函数)为相同的数据提供不同的结果_Python 3.x_Regression_Linear Regression_Piecewise - Fatal编程技术网

Python 3.x Python pwlf(分段线性函数)为相同的数据提供不同的结果

Python 3.x Python pwlf(分段线性函数)为相同的数据提供不同的结果,python-3.x,regression,linear-regression,piecewise,Python 3.x,Regression,Linear Regression,Piecewise,这是我的数据: x array([ 0, 7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84, 91, 98, 105, 112, 119, 126, 133, 140, 147, 154, 161, 168, 175]) y array([0.4 , 0.4 , 0.4 , 0.4 , 0.6 , 0.6 , 0.6 , 0.6 , 0.6 , 0.97, 0.97, 0.97, 0.97,

这是我的数据:

x
array([  0,   7,  14,  21,  28,  35,  42,  49,  56,  63,  70,  77,  84,
        91,  98, 105, 112, 119, 126, 133, 140, 147, 154, 161, 168, 175])

y
array([0.4 , 0.4 , 0.4 , 0.4 , 0.6 , 0.6 , 0.6 , 0.6 , 0.6 , 0.97, 0.97,
       0.97, 0.97, 1.13, 1.13, 1.13, 1.13, 1.13, 0.9 , 0.9 , 0.9 , 0.9 ,
       0.7 , 0.7 , 0.7 , 0.7 ])
我应用了
pwlf
——但每次执行此代码时,我都会得到不同的
fit\u中断

pwlf_model = pwlf.PiecewiseLinFit(x, y ,degree=1)
pwlf_model.fit(4)
首轮

pwlf_model.fit_breaks
array([  0.        ,  58.01861485,  60.07425168, 104.30868782,
       175.        ])
第二轮

pwlf_model.fit_breaks
array([  0.        ,  59.48475228,  59.67460644, 104.30594173,
       175.        ])
第三轮

pwlf_model.fit_breaks
array([  0.        ,  56.60204   ,  62.0270283 , 104.30827438,
       175.        ])
第四轮

pwlf_model.fit_breaks
array([  0.        ,  58.92722066,  59.50363949, 104.30764284,
       175.        ])
为什么呢?模型中有随机步骤吗?
[1] :

看起来用于拟合的方法是随机的。从中,fit调用函数
scipy.optimize.differential\u evolution
。该函数的定义是将其描述为确定函数全局最小值的随机方法


似乎在pwlf使用默认设置的情况下,它并没有完全收敛,或者至少每次都从不同的方向接近收敛。您可能能够编辑关键字,以便优化将对真正的最小值进行更严格的搜索。例如,
atol
设置收敛的绝对容差。您还将
seed
设置为一致的值,以便每次至少获得相同的结果,即使它可能没有找到“真”最小值。请注意,如果您更改了其中一个关键字,则需要明确写出所有其他关键字,因为传递到
fit
**kwargs
似乎覆盖了将传递到
differential\u evolution

的默认值感谢您的明确解释,我将尝试不同的选项