finds a fit a1 f1++an fn to a list of data for functions f1,,fn of variables {x,y,}.


finds a fit vector a that minimizes for a design matrix m.


specifies what fit property prop should be returned.

Details and Options

  • Fit is also known as linear regression or least squares fit.
  • Fit is typically used for fitting combinations of functions to data, including polynomials and exponentials. It provides one of the simplest ways to get a model from data.
  • The best fit minimizes the sum of squares .
  • The data can have the following forms:
  • {v1,,vn}equivalent to {{1,v1},,{n,vn}}
    {{x1,v1},,{xn,vn}}univariate data with values vi at coordinates xi
    {{x1,y1,v1},}bivariate data with values vi and coordinates {xi,yi}
    {{x1,y1,,v1},}multivariate data with values vi at coordinates {xi,yi,}
  • The design matrix m has elements that come from evaluating the functions at the coordinates, . In matrix notation, the best fit minimizes the norm where and .
  • The functions fi should depend only on the variables {x,y,}.
  • The possible fit properties "prop" include:
  • "BasisFunctions"funsthe basis functions
    "BestFit"the best fit linear combination of basis functions
    "BestFitParameters"the vector that gives the best fit
    "Coordinates"{{x1,y1,},}the coordinates of vars in data
    "Data"datathe data
    "FitResiduals"the differences between the model and the fit at the coordinates
    "Function"Function[{x,y,},a1 f1++an fn]best fit pure function
    "PredictedResponse"fitted values for the data coordinates
    "Response"the response vector from the input data
    {"prop1","prop2",} several fit properties
  • Fit takes the following options:
  • NormFunctionNormmeasure of the deviations to minimize
    FitRegularizationNoneregularization for the fit parameters
    WorkingPrecisionAutomaticthe precision to use
  • With NormFunction->normf and FitRegularization->rfun, Fit finds the coefficient vector a that minimizes normf[{a.f(x1,y1,)-v1,,a.f(xk,yk,)-vk}] + rfun[a].
  • The setting for NormFunction can be given in the following forms:
  • normfa function normf that is applied to the deviations
    {"Penalty", pf}sum of the penalty function pf applied to each component of the deviations
    {"HuberPenalty",α}sum of Huber penalty function for each component
    ["DeadzoneLinearPenalty",α}sum of deadzone linear penalty function for each component.
  • The setting for FitRegularization may be given in the following forms:
  • Noneno regularization
    rfunregularize with rfun[a]
    {"Tikhonov", λ}regularize with
    {"LASSO",λ}regularize with
    {"Variation",λ}regularize with
    {"TotalVariation",λ}regularize with
    {"Curvature",λ}regularize with
    {r1,r2,}regularize with the sum of terms from r1,
  • With WorkingPrecision->Automatic, exact numbers given as input to Fit are converted to approximate numbers with machine precision. »


open all close all

Basic Examples  (2)

Here is some data:

Click for copyable input

Find the line that best fits the data:

Click for copyable input
Click for copyable input

Find the quadratic that best fits the data:

Click for copyable input

Show the data with the two curves:

Click for copyable input

Find the best fit parameters given a design matrix and response vector:

Click for copyable input

Generalizations & Extensions  (1)

Options  (6)

Applications  (6)

Properties & Relations  (5)

Possible Issues  (2)

Introduced in 1988
Updated in 2019