shadeless - 8 months ago 92

Python Question

I tried to use SciPy's smoothing univariate spline

`from scipy.interpolate import UnivariateSpline`

spl = UnivariateSpline(x, y)

And I get this error message.

/usr/lib/python3.5/site-packages/scipy/interpolate/fitpack2.py:222: UserWarning:

The maximal number of iterations maxit (set to 20 by the program)

allowed for finding a smoothing spline with fp=s has been reached: s

too small.

There is an approximation returned but the corresponding weighted sum

of squared residuals does not satisfy the condition abs(fp-s)/s < tol.

warnings.warn(message)

How can I redefine the maxit parameter? I haven't been able to find anything in the SciPy manual except that it's a keyword in class scipy.odr.ODR. I haven't had much luck though.

Answer

You cannot change this parameter, it's fixed deep down in the FITPACK code:

https://github.com/scipy/scipy/blob/master/scipy/interpolate/fitpack/curfit.f#L220

In principle, you could modify the Fortran sources and recompile scipy, but this is almost surely not what you want to do. Instead, you could use the `s`

parameter of the UnivariateSpline (or splrep, for that matter) to see if you're getting something useful given your data `x`

and `y`

.

And, by the way, ODR has nothing to do with this.

Source (Stackoverflow)