Questions tagged [least-squares]

Refers to a general estimation technique that selects the parameter value to minimize the squared difference between two quantities, such as the observed value of a variable, and the expected value of that observation conditioned on the parameter value. Questions about the theory behind least-squares should utilize the Cross Validated (https://stats.stackexchange.com/questions) Stack Exchange site.

Overview

From the "Least squares" article on Wikipedia:

The method of least squares is a standard approach to the approximate solution of overdetermined systems, i.e., sets of equations in which there are more equations than unknowns. "Least squares" means that the overall solution minimizes the sum of the squares of the errors made in the results of every single equation.

Least squares problems fall into two categories: linear or ordinary least squares and non-linear least squares, depending on whether or not the residuals are linear in all unknowns. The linear least-squares problem occurs in statistical regression analysis; it has a closed-form solution. A closed-form solution (or closed-form expression) is any formula that can be evaluated in a finite number of standard operations. The non-linear problem has no closed-form solution and is usually solved by iterative refinement; at each iteration the system is approximated by a linear one, and thus the core calculation is similar in both cases.

Other References

Least squares methods are treated in many introductory statistics resources and textbooks, but there are also advanced resources dedicated only to the subject, for example:

Tag usage

Questions on should be about implementation and programming problems, not about the statistical or theoretical properties of the technique. Consider whether your question might be better suited to Cross Validated, the StackExchange site for statistics, machine learning and data analysis.

1013 questions
10
votes
3 answers

Ruby Library for doing Linear or NonLinear Least Squares Approximation?

Is there a Ruby library that allows me to do either linear or non-linear least squares approximation of a set of data. What I would like to do is the following: Given a series of [x,y] data points Generate a linear or non linear least squares…
Peter C
  • 101
  • 1
  • 4
10
votes
2 answers

L1 norm instead of L2 norm for cost function in regression model

I was wondering if there's a function in Python that would do the same job as scipy.linalg.lstsq but uses “least absolute deviations” regression instead of “least squares” regression (OLS). I want to use the L1 norm, instead of the L2 norm. In fact,…
Sara .Eft
  • 101
  • 1
  • 5
10
votes
1 answer

perform Deming regression without intercept

I would like to perform Deming regression (or any equivalent of a regression method with uncertainties in both X and Y variables, such as York regression). In my application, I have a very good scientific justification to deliberately set the…
agenis
  • 8,069
  • 5
  • 53
  • 102
10
votes
5 answers

Dynamic Programming Algorithm for Segmented Least Squares

I've been trying to implement this algorithm in Python for a few days now. I keep coming back to it and just giving up and getting frustrated. I don't know whats going on. I don't have anyone to ask or anywhere to go for help so I've come here. PDF…
10
votes
3 answers

Difference between scipy.leastsq and scipy.least_squares

I was wondering what the difference between the two methods scipy.optimize.leastsq and scipy.optimize.least_squares is? When I implement them they yield minimal differences in chi^2: >>> solution0 = ((p0.fun).reshape(100,100)) >>> # p0.fun are the…
Sebastiano1991
  • 867
  • 1
  • 10
  • 26
10
votes
1 answer

Difference in Differences in Python + Pandas

I'm trying to perform a Difference in Differences (with panel data and fixed effects) analysis using Python and Pandas. I have no background in Economics and I'm just trying to filter the data and run the method that I was told to. However, as far…
pceccon
  • 9,379
  • 26
  • 82
  • 158
10
votes
2 answers

Is linear regression the same thing as ordinary least squares in SPSS?

I want to use a linear regression model, but I want to use ordinary least squares, which I think it is a type of linear regression. The software I use is SPSS. It only has linear regression, partial least squares and 2-stages least squares. I have…
user41000
  • 285
  • 1
  • 6
  • 13
10
votes
3 answers

Fitting a line that passes through the origin (0,0) to data

I have a set of points (x,y) and I need to find the line of best-fit that passes through the origin using MATLAB.
dr_rk
  • 4,395
  • 13
  • 48
  • 74
10
votes
6 answers

Plane fitting to 4 (or more) XYZ points

I have 4 points, which are very near to be at the one plane - it is the 1,4-Dihydropyridine cycle. I need to calculate distance from C3 and N1 to the plane, which is made of C1-C2-C4-C5. Calculating distance is OK, but fitting plane is quite…
XuMuK
  • 564
  • 4
  • 11
  • 32
10
votes
2 answers

Need to fit polynomial using chebyshev polynomial basis

I have been fitting linear least-squares polynomials to data using the polyfit function in matlab. From what I read, this uses standard polynomial basis (monomial basis). I have read that using Chebyshev polynomial basis to fit leads to greater…
user1593853
  • 127
  • 1
  • 1
  • 7
10
votes
2 answers

Use of curve_fit to fit data

I'm new to scipy and matplotlib, and I've been trying to fit functions to data. The first example in the Scipy Cookbook works fantastically, but when I am trying it with points read from a file, the initial coefficients I give (p0 below) never seem…
Ironil
  • 171
  • 2
  • 2
  • 12
9
votes
9 answers

Fitting an ellipsoid to 3D data points

I have a large set of 3D data points to which I want to fit to an ellipsoid. My maths is pretty poor, so I'm having trouble implementing the least squares method without any math libraries. Does anyone know of or have a piece of code that can fit an…
Hannesh
  • 7,256
  • 7
  • 46
  • 80
9
votes
1 answer

Efficient computation of the least-squares algorithm in NumPy

I need to solve a large set of linear systems, in the least-squares sense. I am having trouble in understanding the difference in computational efficiency of numpy.linalg.lstsq(a, b), np.dot(np.linalg.pinv(a), b) and the mathematical…
blaz
  • 4,108
  • 7
  • 29
  • 54
9
votes
1 answer

Least-squares minimization within threshold in MATLAB

The cvx suite for MATLAB can solve the (seemingly innocent) optimization problem below, but it is rather slow for the large, full matrices I'm working with. I'm hoping this is because using cvx is overkill, and that the problem actually has an…
Geoff
  • 1,202
  • 10
  • 18
9
votes
3 answers

How to use least squares with weight matrix?

I know how to solve A.X = B by least squares using Python: Example: A=[[1,1,1,1],[1,1,1,1],[1,1,1,1],[1,1,1,1],[1,1,0,0]] B=[1,1,1,1,1] X=numpy.linalg.lstsq(A, B) print X[0] # [ 5.00000000e-01 5.00000000e-01 -1.66533454e-16 …
Eric H.
  • 2,152
  • 4
  • 22
  • 34
1 2
3
67 68