Docsity

Linear Regression - Computational Methods - Lecture Notes | CMSC 460, Study notes of Computer Science

Partial preview of the text

Download Linear Regression - Computational Methods - Lecture Notes | CMSC 460 and more Study notes Computer Science in PDF only on Docsity!

Computational Methods CMSC/AMSC/MAPL 460

Least squares method: linear regression

Ramani Duraiswami, Dept. of Computer Science

Fitting data to a model

•^

Practical science involves lots of fitting of data to models

-^

Difference between fitting and interpolation?– Interpolation, the fit function passes through the point– Fitting, the fit function satisfies some error criterion

-^

Tasks arise commonly in science– Fit straight lines and curves to data– More generally fit data to a parametric model

-^

Parametric: Model contains parameters– Job of fitting is to estimate the parameters that “best” make the

model fit the data

  • “best”

Æ

define best

•^

Simplest example of model fitting problem– Linear regression

Relationships among Variables

•^

In much science we seek relations between variables

One variable is used to “explain” another variable

X

Variable

Independent VariableExplaining VariableExogenous Variable

Predictor Variable

Y

Variable

Dependent VariableResponse VariableEndogenous VariableCriterion Variable

1

slope:

b

intercept

a

bX a

Y

=

:s

prediction

errorless had we If

X

Y

Simple Least-Squares Regression

X

Y

Estimated Regression Line

X

Y

Estimated Regression Line

i

i

i^

y

y

e^

ˆ −

=

y^ i ˆ yi

x^ i

bX a Y^

= ˆ

:

Line

Regression the of

Equation

Linear Systems

A

x

b

= =

Square system:

  • unique solution• Gaussian elimination

Rectangular system ??

  • underconstrained:

infinity of solutions Minimize |Ax-b|

2

  • overconstrained:

no solution

A

x

b

For straight line fitting we need to find two parameters.However each of the data points provides an estimate of the error

How do we find a and b?

(^

)^

[^

]

(^

)

∑

∑

=

=

N^1 i

2

N^1 i

2

iduals

errors/res

squared of

sum the

minimize to ,

Find

a

bx

y

e

b a

i

i

In Least-Squares Regression: i

In Least-Squares Regression:

(^

(^

)^

X b Y a X X

Y
Y
X
X

b

N i

i

N i

i

i

= =^

1

2

1

=^

=

=^

=

=

⎞ ⎟ ⎠

⎛ ⎜ ⎝ −

⎞ ⎟ ⎠

⎛⎞ ⎜⎟ ⎝⎠

⎛ ⎜ ⎝ −

=

N i

N i

i

i

N i

N i

i

N i

i

i i

X

X

N

Y X Y X N b

1

2

1

2

1

1

1

ComputationalFormula

Linear models

•^

Some models considered are “linear” or “separable”– (does not mean straight lines)– Means that we can separate the “structure” and “parameters” as

a matrix-vector product

  • “structure” forms a matrix and “parameters” a vector -^

Goal of model fitting: find the parameters

-^

Question: Is the Gaussian model a linear one?– Can be made separable by taking logs– However if there are sums of gaussians or exponentials the

model is not separable

Other Norms

•^

Here we fit using the “least-squares” or L

2

norm

•^

Could minimize the residual in other norms

-^

For example we may have more confidence in some data,and want to be sure that their residual is lower– Attach a weight to each residual

-^

Or we may like the 1-norm or infinity norm better

Normal equations

•^

The system A

t^ A x = A

tb

is called the Normal equations

-^

Can solve least squares problems using these

-^

For A size m × n and x of size n and b of size m what arethe dimensions of the normal equations?– n × n

-^

Solve via LU decomposition

-^

Is this a good idea?– Somewhat expensive as we have to form A

t^ A which involves

matrix multiplication and then solution

  • More importantly it is poorly conditioned– cond(A

t A) = (cond(A))

2