Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation for s in UnivariateSpline is confusing #4975

Closed
cancan101 opened this issue Jun 17, 2015 · 11 comments · Fixed by #16860
Closed

Documentation for s in UnivariateSpline is confusing #4975

cancan101 opened this issue Jun 17, 2015 · 11 comments · Fixed by #16860
Labels
Documentation Issues related to the SciPy documentation. Also check https://github.com/scipy/scipy.org scipy.interpolate
Milestone

Comments

@cancan101
Copy link
Contributor

From the docs:

w : (N,) array_like, optional
Weights for spline fitting. Must be positive. If None (default), weights are all equal.

s : float or None, optional
Positive smoothing factor used to choose the number of knots. Number of knots will be increased until the smoothing condition is satisfied:
If None (default), s = len(w) which should be a good value if 1/w[i] is an estimate of the standard deviation of y[i]. If 0, spline will interpolate through all data points.

I interpret that to mean that if w is not specified, then s=0 should be the same as s=None but that does not seem to be the case.

@josef-pkt
Copy link
Member

I read this as s = nobs = len(data) in this case
implied weights if w is not specified are w = np.ones(len(data))

guessing based on part of docs in description

@cancan101
Copy link
Contributor Author

@josef-pkt how do you think s will differ when you set it to None vs 0 when w=None?

@ev-br
Copy link
Member

ev-br commented Jun 17, 2015

@cancan101
Copy link
Contributor Author

I know they are not the same. My question is what is actually happening.

@ev-br
Copy link
Member

ev-br commented Jun 17, 2015

The missing piece of documentation is maybe that UnivariateSpline does not do interpolation, it does fitting unless you force interpolation by using s=0.

Regarding what is actually happening, uhm well, here are Fortan level docs: https://github.com/scipy/scipy/blob/master/scipy/interpolate/fitpack/curfit.f#L141

Maybe some of this information could/should be added to python level docs.

EDIT: https://github.com/scipy/scipy/blob/master/scipy/interpolate/src/fitpack.pyf#L263
It seems that the default is w = np.ones_like(x) and s=len(x).

@ev-br ev-br added scipy.interpolate Documentation Issues related to the SciPy documentation. Also check https://github.com/scipy/scipy.org query A question or suggestion that requires further information labels Jun 17, 2015
@josef-pkt
Copy link
Member

if w is None and s is None: s = number_of_observations is my interpretation of the docstring (which sounds too large to me)

@argriffing
Copy link
Contributor

My question is what is actually happening.

This has already been answered in this thread, but I agree that the interface is confusing. You might think if you don't want weights or smoothing then you just don't provide w or s, but in fact this will use default (equal) weights and default (nonzero) smoothing. So if you want to disable smoothing then you have to set it to zero explicitly.

@josef-pkt
Copy link
Member

correction: s=len(x) is not too large because s is sum of squares and not mean.
From the docstring this would mean it's designed for standardized variables where variance (ss / nobs) is one

@josef-pkt
Copy link
Member

but I thought/think s is residual sum of squares not sum of squares of y.

@ev-br
Copy link
Member

ev-br commented Jun 21, 2015

@cancan101 viewing this as a documentation issue, what would you suggest to add/remove/improve?
I don't think we should change the behavior of the UnivariateSpline (as, erm, quirky it is)

@cancan101
Copy link
Contributor Author

Perhaps mention that s=0 results in an interpolating spline whereas the default of s=None yields a smoothing spline that uses all of the points?

@rgommers rgommers removed the query A question or suggestion that requires further information label Aug 10, 2019
@ev-br ev-br added this to DOC in scipy.interpolate Apr 29, 2022
scipy.interpolate automation moved this from DOC to Done Aug 19, 2022
@ev-br ev-br added this to the 1.10.0 milestone Aug 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation Issues related to the SciPy documentation. Also check https://github.com/scipy/scipy.org scipy.interpolate
Projects
Development

Successfully merging a pull request may close this issue.

5 participants