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

Finding parameters of model using Levenberg-Marquardt algorithm leastsq

I am trying to find parameters A,B,C to data x,y using model y= Ax^2 sin(x)/cos(x)^C + B I want to use leastsq from scipy.optimize but I've got error. Here is my attempt: x=n.array(x) y=n.array(y) model=lambda tpl,x :(tpl[0]*x**2 *…
wiedzminYo
  • 531
  • 4
  • 11
  • 24
-2
votes
2 answers

Least Squares Algorithm doesn't work

:) I'm trying to code a Least Squares algorithm and I've come up with this: function [y] = ex1_Least_Squares(xValues,yValues,x) % a + b*x + c*x^2 = y points = size(xValues,1); A = ones(points,3); b = zeros(points,1); for i=1:points A(i,1)…
syfantid
  • 366
  • 5
  • 20
-2
votes
1 answer

MATLAB: Approximate tomorrow's temperature with 2nd, 3rd and 4th polynomial using the Least Squares method

The following is Exercise 3 of a Numerical Analysis task I have to do as part of my university course on the subject. Find an approximation of tomorrow's temperature based on the last 23 values of hourly temperature of your city ( Meteorological…
Dimitris Sfounis
  • 2,400
  • 4
  • 31
  • 46
-2
votes
2 answers

Equation of the least-squares parabola for data set. (FORTRAN)

Original Question: To find the equation of the parabola y = A + Bx + Cx^2 that best fits a set of n data points, the values of A, B, and C must be determined for which the sum of the squares of the deviations of the observed y-values from the…
Joe
  • 1
  • 2
-3
votes
1 answer

Constrained Least Squares with Numpy and Python only

How to do constrained Least Squares only using numpy. Is there any way to incorporate constraints into numpy.linalg.lstsq() or is there any numpy+Python workaround to do constrained Least Squares? I know that I can do this easily with cvxpy and…
-3
votes
1 answer

Fit a line through some 3D points

Good morning, so what I have is a bunch of 3D points. Now I just want to fit a line through it without setting one axis to zero! I could not find anything, can you help me? (If it helps I use Matlab) Is Ordinary least square fitting an option? I…
-3
votes
1 answer

TypeError: Can not understand

I am fitting a very simple curve having three points. with leastsq method, following all the rules. But still I am getting error. I cannot understand. Can anyone help. Thank you so much import numpy as np import matplotlib.pyplot as plt from…
Esha
  • 1
  • 2
-4
votes
1 answer

Least Square Fitting Algorithm

I am writing an algorithm in Python to fit a data (I need to write my own algorithm). But I have a problem with the arrays. For example: import math x=[2,1] a=sum([x[i]*x[i] for i in range(len(x))]) It is working. However when I tried to divide, it…
1 2 3
67
68