's coefficient not working for my univariatespline

I'm changing my s coefficient but the shape of my interpolation won't change, why is this?

import scipy.interpolate as inter
import numpy as np
import pylab as plt

x = [4.087671, 7.923288 , 10.093151, 10.594521]
y = [0.01701,0.02494,0.02803,0.03063]

xx = np.arange(1, 13.01, 0.1)
s1 = inter.InterpolatedUnivariateSpline(x, y)
s2 = inter.UnivariateSpline(x, y, s=3)
s2crazy = inter.UnivariateSpline(x, y, s=5e8)

plt.plot(x, y, 'bo', label='Data')
plt.plot(xx, s1(xx), 'k-', label='Spline')
plt.plot(xx, s2(xx), 'r-', label='Spline, fit')
plt.plot (xx, s2crazy(xx), 'r--', label='Spline, fit, s=5e8')
plt.legend()
plt.xlabel('x')
plt.ylabel('y')
plt.show()

enter image description here



Solution 1:[1]

It works, but there is nothing to smooth. You are already fitting the data.

Try adding a few more points:

import scipy.interpolate as inter
import numpy as np
import pylab as plt

x = [4.087671, 7.923288, 8.593151, 10.093151, 10.594521]
y = [0.01701,  0.02494,   0.02103,   0.02803,    0.03063]

xx = np.arange(1, 13.01, 0.1)
s1 = inter.InterpolatedUnivariateSpline(x, y)
s2 = inter.UnivariateSpline(x, y, s=0.1)
s2crazy = inter.UnivariateSpline(x, y, s=5e8)

plt.plot(x, y, 'bo', label='Data')
plt.plot(xx, s1(xx), 'k-', label='Spline')
plt.plot(xx, s2(xx), 'r-', label='Spline, fit')
plt.plot (xx, s2crazy(xx), 'r--', label='Spline, fit, s=5e8')
plt.legend()
plt.xlabel('x')
plt.ylabel('y')
plt.show()

enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Florian Fasmeyer