title: Use UnivariateSpline to fit data tightly
body: <p>I have a bunch of x, y points that represent a sigmoidal function:</p>
  
  <pre><code>x=[ 1.00094909  1.08787635  1.17481363  1.2617564   1.34867881  1.43562284
    1.52259341  1.609522    1.69631283  1.78276102  1.86426648  1.92896789
    1.9464453   1.94941586  2.00062852  2.073691    2.14982808  2.22808316
    2.30634034  2.38456905  2.46280126  2.54106611  2.6193345   2.69748825]
  y=[-0.10057627 -0.10172142 -0.10320428 -0.10378959 -0.10348456 -0.10312503
   -0.10276956 -0.10170055 -0.09778279 -0.08608644 -0.05797392  0.00063599
    0.08732999  0.16429878  0.2223306   0.25368884  0.26830932  0.27313931
    0.27308756  0.27048902  0.26626313  0.26139534  0.25634544  0.2509893 ]
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/22AGL.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/22AGL.png" alt="Data"></a></p>
  
  <p>I use <code>scipy.interpolate.UnivariateSpline()</code> to fit to some cubic spline as follows:</p>
  
  <pre><code>from scipy.interpolate import UnivariateSpline
  s = UnivariateSpline(x, y, k=3, s=0)
  
  xfit = np.linspace(x.min(), x.max(), 200)
  plt.scatter(x,y)
  plt.plot(xfit, s(xfit))
  plt.show()
  </code></pre>
  
  <p>This is what I get: <a href="https://i.stack.imgur.com/Af2PQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Af2PQ.png" alt="Fit"></a></p>
  
  <p>Since I specify <code>s=0</code>, the spline adheres completely to the data, but there are too many wiggles. Using a higher <code>k</code> value leads to even more wiggles. </p>
  
  <p>So my questions are -- </p>
  
  <ol>
  <li>How should I correctly use <code>scipy.interpolate.UnivariateSpline()</code> to fit my data? More precisely, how do I make the spline minimise its wiggling?</li>
  <li>Is this even the correct choice for this kind of a sigmoidal function? Should I be using something like <code>scipy.optimize.curve_fit()</code> with a trial <code>tanh(x)</code> function instead?</li>
  </ol>