0
votes

I have multiple sets of data to which I am fitting a Univariate Spline in Scipy:

spl = UnivariateSpline(x, y)
domain = np.linspace(min(x), max(x)), 10000)
plt.scatter(x, y, c='r', marker='x')
plt.plot(domain, spl(domain), 'b-')

This is a "noisy" example set for which the trend in y MUST increase with x, but is not what the spline is returning (see below).

Is there a way to evaluate this spline in such a way that its gradient is ALWAYS POSITIVE? This would be very helpful.

Red points: data, Blue curve: output of spline

1
is there a reason why you have to use UnivariateSpline? Looks more like a logarithmic to me.DrBwts

1 Answers

0
votes

Not out of the box.

FITPACK, the fortran library which UnivariateSpline wraps, has some constrained spline fitting, but it is not exposed to python level. If you do wrap it, consider sending a pull request.