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
0
votes
1 answer

calculating y_pred in least square regression (R)?

I'm having trouble calculating the y_pred in the least square regression. The idea is something like: mydata <- read.csv("G:\\sample.csv",header=T) x<-rep(mydata$wavelength,each=119) y<-c(mydata$v1,....mydata$v119) lm(y~x) A sample data can be…
Vicki1227
  • 489
  • 4
  • 6
  • 19
0
votes
1 answer

scipy polyfit x, y , weights =error bars

I would like to fit a line that uses the inverse of the error bars as weights. I binned my data x and y, into 10 bins ( ~26 points each ) and took their mean. This is not a matrix of values so polyfit isn't happy with that. # note I didn't test…
wbg
  • 866
  • 3
  • 14
  • 34
0
votes
1 answer

fit a curve with model equation numpy

I am trying to reproduce a curve with a model equation using non-linearleast square procedure to get out a certain "beta" value. The y and x experimental data are two 1D numpy arrays of the same size, namely "a" and "angle_plot" respectively. The…
diegus
  • 1,168
  • 2
  • 26
  • 57
0
votes
2 answers

Least squares fit, unknown intercerpt

I have three data points through which I have to fit a straight line of the form Y=m*X+C. I want the line to have pre-determined slope 'm' but the constant'C' can change to get the least error while fitting using matlab. Can someone help me out?
labalala
  • 17
  • 6
0
votes
1 answer

Interactive curve fitting with MATLAB using custom GUI?

I find examples the best way to demonstrate my question. I generate some data, add some random noise, and fit it to get back my chosen "generator" value... x = linspace(0.01,1,50); value = 3.82; y = exp(-value.*x); y = awgn(y,30); options =…
Steve Hatcher
  • 715
  • 11
  • 27
0
votes
2 answers

interpolate.splrep error: 'knots must be given for task =-1'

I'm trying to find a least squared cubic spline fit of data using the following code: from scipy import interpolate plt.subplot(223) l_hits = np.array(l_hits) list1 = np.log(l_hits) knots = list1.sort() xnew = np.arange(min(l_bins), max(l_bins)) tck…
user2954167
  • 155
  • 1
  • 3
  • 14
0
votes
2 answers

Uses for secondary returns of scipy.optimize.leastsq?

I have been using scipy.optimize.leastsq quite a bit lately, but whenever I call it I only use the return "x" (the solution) from this long list of return values. I can't see myself needing any of the other values it returns. I'm curious, has anyone…
Sam M.
  • 31
  • 2
0
votes
1 answer

Why is my python lmfit leastsq fitting function being passed too many arguments?

I've tried to search for someone making the same mistake as me, but have had no joy! It's also my 1st post, so I apologise if it's badly explained or directed. Advice welcome. The problem I am solving is: Finding the position of a receiver of some…
mrscruff
  • 47
  • 1
  • 5
0
votes
2 answers

Exponential least square fitting on Scilab

I have two arrays x and y, and would like to fit an exponential to them with a(1) and a(2) as fitting parameters. I wrote a test code as follows: k=6.63e-34*3e8/1.38e-23 x=[1;2;3;4;5;6;7;8;9;10] y=[280;320;369.22772;391.25743;414.74257; …
user2993263
  • 55
  • 1
  • 7
0
votes
1 answer

non linear least squares in 3D space in MATLAB?

For 2D space I have used lsqcurvefit. But for 3D space I haven't found any easy function. the function I'm trying to fit has the form something like this: z = f(x,y) = a+b*x+c*e^(-y/d) I would like to know if there is any tool box or function for…
ponir
  • 447
  • 7
  • 20
0
votes
2 answers

How to interpolate 3D points computed from a Kinect to get a ball trajectory?

I'm getting 3D points from the Kinect via OpenNI. Let's say I have : X = [93.7819,76.8463,208.386,322.069,437.946,669.999] Y = [-260.147,-250.011,-230.717,-211.104,-195.538,-189.851] Z = [958,942,950,945,940,955] That's the points I was able to…
Kriegalex
  • 423
  • 6
  • 17
0
votes
1 answer

Least square straight line intersection

I have 2 cluster of points, each of which are derived from a RANSAC line fitting (among several points in the set). Solving the system of equations, I can retrieve the parameters for the two lines in least square fashion. I want to determine if…
ayan.c
  • 263
  • 2
  • 7
  • 17
0
votes
1 answer

ipython non-linear least squares with constraints equations

I am new to iPython, and need to solve a specific curve fitting problem, I have the concept but my programming knowledge is yet too limited. I have experimental data (x, y) to fit to an equation (curve fitting) with four coefficients (a,b,c,d), I…
zircon_34
  • 3
  • 2
0
votes
1 answer

I used least square method but matlab return compeletly wrong answer

I must solve an over constrained problem (Equations more than unknowns). So I have to use least square method. First I create coefficient matrix .It is a 225*375 matrix. For inversing, I use pinv() function and then multiply it in load matrix . My…
mohsen
  • 23
  • 1
0
votes
1 answer

Scipy.optimize.leastsq returns the initial guess not optimization parameters

I am trying to use leastsq from the scipy.optimize module to find a best fit line, where there are 3 unknown parameters. I have written out the code however the program runs and returns the initial guess as the optimization parameters (essentially…
user3546200
  • 269
  • 1
  • 3
  • 10