scipy.interpolate.UnivariateSpline not smoothing regardless of parameters

后端 未结 4 650
死守一世寂寞
死守一世寂寞 2021-01-01 04:31

I\'m having trouble getting scipy.interpolate.UnivariateSpline to use any smoothing when interpolating. Based on the function\'s page as well as some previous posts, I beli

4条回答
  •  轮回少年
    2021-01-01 05:05

    Short answer: you need to choose the value for s more carefully.

    The documentation for UnivariateSpline states that:

    Positive smoothing factor used to choose the number of knots. Number of 
    knots will be increased until the     smoothing condition is satisfied:
    sum((w[i]*(y[i]-s(x[i])))**2,axis=0) <= s
    

    From this one can deduce that "reasonable" values for smoothing, if you don't pass in explicit weights, are around s = m * v where m is the number of data points and v the variance of the data. In this case, s_good ~ 5e7.

    EDIT: sensible values for s depend of course also on the noise level in the data. The docs seem to recommend choosing s in the range (m - sqrt(2*m)) * std**2 <= s <= (m + sqrt(2*m)) * std**2 where std is the standard deviation associated with the "noise" you want to smooth over.

提交回复
热议问题