DOC: interpolate.make_splrep: result depends on scaling of data
Author: jakobhaimecCreated Apr 28, 2025Updated Sep 18, 2026
Labelsscipy.interpolateDocumentationsustain-2026
Describe your issue.
The smoothing spline generated by scipy.signal.make_splrep depends on the scaling of the data provided as y. This is not intuitive to the user and represents a significant risk when the method is applied to data of different scaling.
I am aware that this issue is somewhat addressed in the documentation, stating that the "s" - parameter depends on the standard deviation of the data. However, I wonder if there is a way to make the method more robust, e.g. by changing the default weights from ones to np.ones(len(x))/np.sqrt(np.std(y))
Reproducing Code Example
x = np.arange(0, 2*np.pi+np.pi/4, 2*np.pi/16)
rng = np.random.default_rng()
yraw = np.sin(x) + 0.4*rng.standard_normal(size=len(x))
xnew = np.arange(0, 9/4, 1/50) * np.pi
#weights=np.ones(len(x))/np.sqrt(np.std(y)) #this makes result independent from scaling
weights=np.ones(len(x))
plt.figure()
plt.plot(x, yraw, 'o')
y = 1.0*yraw
plt.plot(xnew, sp.interpolate.make_splrep(x, y, w=weights,s=5)(xnew), '-',label='scaling = 1')
y = 10*yraw
weights=10*np.ones(len(x))/np.sqrt(np.std(y))
plt.plot(xnew, sp.interpolate.make_splrep(x, y/10, w=weights,s=5)(xnew), '-',label='scaling = 10')
y = 0.1*yraw
weights=10*np.ones(len(x))/np.sqrt(np.std(y))
plt.plot(xnew, sp.interpolate.make_splrep(x, y/0.1, w=weights,s=5)(xnew), '-',label='scaling = 0.1')
plt.legend()
plt.show()Error message
no error messageSciPy/NumPy/Python version and system information
scipy 1.15.2, numpy 1.26.4, python 3.10.12Source: scipy/scipy