我在插值时无法让 scipy.interpolate.UnivariateSpline 使用任何平滑。基于函数的页面 http://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.UnivariateSpline.html#scipy.interpolate.UnivariateSpline以及一些以前的帖子 https://stackoverflow.com/questions/7906126/spline-representation-with-scipy-interpolate-poor-interpolation-for-low-amplitu,我相信它应该提供平滑s
范围。
这是我的代码:
# Imports
import scipy
import pylab
# Set up and plot actual data
x = [0, 5024.2059124920379, 7933.1645067836089, 7990.4664106277542, 9879.9717114947653, 13738.60563208926, 15113.277958924193]
y = [0.0, 3072.5653360000988, 5477.2689107965398, 5851.6866463790966, 6056.3852496014106, 7895.2332350173638, 9154.2956175610598]
pylab.plot(x, y, "o", label="Actual")
# Plot estimates using splines with a range of degrees
for k in range(1, 4):
mySpline = scipy.interpolate.UnivariateSpline(x=x, y=y, k=k, s=2)
xi = range(0, 15100, 20)
yi = mySpline(xi)
pylab.plot(xi, yi, label="Predicted k=%d" % k)
# Show the plot
pylab.grid(True)
pylab.xticks(rotation=45)
pylab.legend( loc="lower right" )
pylab.show()
结果如下:
我已经尝试过一系列s
值(0.01、0.1、1、2、5、50)以及显式权重,设置为相同的值(1.0)或随机。我仍然无法得到任何平滑,并且结的数量始终与数据点的数量相同。特别是,我正在寻找像第四点(7990.4664106277542、5851.6866463790966)这样的异常值进行平滑。
是因为我没有足够的数据吗?如果是这样,是否有类似的样条函数或聚类技术可以应用来实现这几个数据点的平滑?