question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DOC: optimize.least_squares: better name for default `loss`?

See original GitHub issue

Hi everybody, And thank you all for the great job. I’ve a question about how curve_fit() solves least squares problems when boundaries are provided.
Specifically, reading the docs here (https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.curve_fit.html) it is explicitly said: “Use non-linear least squares to fit a function, f, to data.” However, and please correct me if I’m wrong, if the problem involves boundaries, the function calls least_squares(), that according to the docs (https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.least_squares.html#scipy.optimize.least_squares) by default has method='trf' and loss='linear', therefore the problem is addressed as “a standard least-squares problem”. So, if I understood correctly, by default in curve_fit() if we don’t pass an alternative loss function supported by least_squares() we are treating a case of a standard linear least squares. If this is the case, IMHO the docs of curve_fit() would be more precise if rephrased as: “Use linear least squares to fit a function, f, to data. Supports non-linear least squares.”

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
mdhabercommented, Dec 11, 2022

Thanks. If it comes up again, we’ll consider changing something. For now, it says “‘linear’…Gives a standard least-squares problem”, which is clear enough, whatever “linear” is supposed to refer to. So I’ll go ahead and close.

1reaction
steppicommented, Dec 11, 2022

The strings that are accepted by loss were selected to correspond with the overall “loss function”; they are not descriptions of rho. Therefore, even though rho(x) = x is an identity operation, 'l2' is a better name for rho(x) = x than 'identity' because it leads to an L2 loss function. And 'l2' is a better name than 'linear' because 'linear' describes neither rho nor the loss function.

Right, every string besides 'linear' refers to the overall cost function, not rho. I think 'l2' would be a better name because it follows the same convention as 'soft_l1', 'huber', etc.

(Would “quadratic” also work?)

Yes, that seems fine to me.

But on the other hand, the function name is least_squares. With that in mind, maybe loss should describe what is done with the squared errors. In that case, 'linear' makes some sense : the loss function is a linear combination of the squares of the errors (with all coefficients 1)?

Yes, in isolation it makes sense. It just doesn’t follow the same convention as the other strings, which all describe the overall cost function. I think that’s a little confusing, although maybe it’s not worth spending the effort to change things.

Read more comments on GitHub >

github_iconTop Results From Across the Web

scipy.optimize.least_squares — SciPy v1.9.3 Manual
Method 'lm' supports only 'linear' loss. Value of soft margin between inlier and outlier residuals, default is 1.0.
Read more >
scipy/least_squares.py at main - optimize - GitHub
Method 'lm' supports only 'linear' loss. f_scale : float, optional. Value of soft margin between inlier and outlier residuals, default.
Read more >
SciPy.optimize.least_squares() Objective Function Questions
Basically, I take stopwatch lap measurements of the roulette ball spinning on the wheel. For each successive lap, the lap time will increase ......
Read more >
Least-Squares models and their applications - scipy.optimize
Least-Squares models and their applications - scipy. optimize Minimizing a function using Least-Squares.Solving large-scale system of ...
Read more >
What are the use cases for non-linear residuals ...
Now I'm wondering what are the use cases for this non-standard least-squares formulation? The documentation mentions that for example arctan ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found