regularization the problem of overfitting machine learning

23
Regularizat ion The problem of overfitting Machine Learning

Upload: annis-mccoy

Post on 14-Jan-2016

254 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Regularization The problem of overfitting Machine Learning

RegularizationThe problem ofoverfitting

Machine Learning

Page 2: Regularization The problem of overfitting Machine Learning

Andrew Ng

Example: Linear regression (housing prices)

Overfitting: If we have too many features, the learned hypothesis may fit the training set very well ( ), but fail to generalize to new examples (predict prices on new examples).

Pric

e

Size

Pric

e

Size

Pric

e

Size

Page 3: Regularization The problem of overfitting Machine Learning

Andrew Ng

Example: Logistic regression

( = sigmoid function)

x1

x2

x1

x2

x1

x2

Page 4: Regularization The problem of overfitting Machine Learning

Andrew Ng

Addressing overfitting:

Pric

e

Size

size of houseno. of bedroomsno. of floorsage of houseaverage income in neighborhoodkitchen size

Page 5: Regularization The problem of overfitting Machine Learning

Andrew Ng

Addressing overfitting:

Options:1. Reduce number of features.

― Manually select which features to keep.― Model selection algorithm (later in course).

2. Regularization.― Keep all the features, but reduce magnitude/values of

parameters .― Works well when we have a lot of features, each of

which contributes a bit to predicting .

Page 6: Regularization The problem of overfitting Machine Learning
Page 7: Regularization The problem of overfitting Machine Learning

RegularizationCost function

Machine Learning

Page 8: Regularization The problem of overfitting Machine Learning

Andrew Ng

Intuition

Suppose we penalize and make , really small.

Pric

e

Size of house

Pric

e

Size of house

Page 9: Regularization The problem of overfitting Machine Learning

Andrew Ng

Small values for parameters ― “Simpler” hypothesis― Less prone to overfitting

Regularization.

Housing:― Features: ― Parameters:

Page 10: Regularization The problem of overfitting Machine Learning

Andrew Ng

Regularization.

Pric

e

Size of house

Page 11: Regularization The problem of overfitting Machine Learning

Andrew Ng

In regularized linear regression, we choose to minimize

What if is set to an extremely large value (perhaps for too large for our problem, say )?

Pric

e

Size of house

Page 12: Regularization The problem of overfitting Machine Learning
Page 13: Regularization The problem of overfitting Machine Learning

RegularizationRegularized linear regression

Machine Learning

Page 14: Regularization The problem of overfitting Machine Learning

Regularized linear regression

Page 15: Regularization The problem of overfitting Machine Learning

Andrew Ng

Gradient descentRepeat

Page 16: Regularization The problem of overfitting Machine Learning

Andrew Ng

Normal equation

Page 17: Regularization The problem of overfitting Machine Learning

Andrew Ng

Suppose ,Non-invertibility (optional/advanced).

(#examples) (#features)

If ,

Page 18: Regularization The problem of overfitting Machine Learning
Page 19: Regularization The problem of overfitting Machine Learning

RegularizationRegularized logistic regression

Machine Learning

Page 20: Regularization The problem of overfitting Machine Learning

Andrew Ng

Regularized logistic regression.

Cost function:x1

x2

Page 21: Regularization The problem of overfitting Machine Learning

Andrew Ng

Gradient descentRepeat

Page 22: Regularization The problem of overfitting Machine Learning

Andrew Ng

gradient(1) = [ ];

function [jVal, gradient] = costFunction(theta)

jVal = [ ];

gradient(2) = [ ];

gradient(n+1) = [ ];

code to compute

code to compute

code to compute

code to compute

Advanced optimization

gradient(3) = [ ];code to compute

Page 23: Regularization The problem of overfitting Machine Learning