我正在尝试将多项式拟合到我的数据中,例如
import scipy as sp
x = [1,6,9,17,23,28]
y = [6.1, 7.52324, 5.71, 5.86105, 6.3, 5.2]
并说我知道多项式的次数(例如:3),然后我只使用 scipy.polyfit 方法来获得给定次数的多项式:
++++++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++
fittedModelFunction = sp.polyfit(x, y, 3)
func = sp.poly1d(fittedModelFunction)
++++++++++++++++++++++++++++++++ 问题:++++++++++++++++++++ ++++++++++++++
1) 我怎么知道生成的函数 func 必须始终为正(即对于任何 x,f(x) >= 0)?
2)如何进一步定义约束(例如(本地)最小和最大点的数量等)以获得更好的拟合?
有没有这样的东西:http: //mail.scipy.org/pipermail/scipy-user/2007-July/013138.html 但更准确?