Fit

Fit[data,{f1,,fn},{x,y,}]

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

Fit[{m,v}]

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

Fit[,"prop"]

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
    "DesignMatrix"m
    "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. »

Examples

open all close all

Basic Examples  (2)

Here is some data:

In[1]:=
Click for copyable input

Find the line that best fits the data:

In[2]:=
Click for copyable input
Out[2]=
In[3]:=
Click for copyable input
Out[3]=

Find the quadratic that best fits the data:

In[4]:=
Click for copyable input
Out[4]=

Show the data with the two curves:

In[5]:=
Click for copyable input
Out[5]=

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

In[1]:=
Click for copyable input
Out[1]=

Generalizations & Extensions  (1)

Options  (6)

Applications  (6)

Properties & Relations  (5)

Possible Issues  (2)

Introduced in 1988
(1.0)
|
Updated in 2019
(12.0)