Top Banner
CS 60050 Machine Learning Classification: Logistic Regression Some slides taken from course materials of Andrew Ng
32

ML-03 Logistic Regression - IITKGP

Jan 30, 2022

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: ML-03 Logistic Regression - IITKGP

CS60050MachineLearning

Classification:LogisticRegression

Some slides taken from course materials of Andrew Ng

Page 2: ML-03 Logistic Regression - IITKGP

AndrewNg

Classification

Email:Spam/NotSpam?OnlineTransactions:Fraudulent /Genuine?Tumor:Malignant/Benign?

0:“NegativeClass”(e.g.,benigntumor)1:“PositiveClass”(e.g.,malignanttumor)

Page 3: ML-03 Logistic Regression - IITKGP

AndrewNg

TumorSize

Malignant?

(Yes)1

(No)0

Canwesolvetheproblemusinglinearregression?

Page 4: ML-03 Logistic Regression - IITKGP

AndrewNg

TumorSize

Thresholdclassifieroutput at0.5:

If,predict“y=1”

If,predict“y=0”

Malignant?

(Yes)1

(No)0

Canwesolvetheproblemusinglinearregression?E.g., fitastraightlineanddefineathresholdat0.5

Page 5: ML-03 Logistic Regression - IITKGP

AndrewNg

TumorSize

Thresholdclassifieroutput at0.5:

If,predict“y=1”

If,predict“y=0”

Malignant?

(Yes)1

(No)0

Canwesolvetheproblemusinglinearregression?E.g., fitastraightlineanddefineathresholdat0.5

Failureduetoaddinganewpoint

Page 6: ML-03 Logistic Regression - IITKGP

AndrewNg

Classification:y=0or1

canbe>1or<0

LogisticRegression:

Anotherdrawbackofusinglinearregressionforthisproblem

Whatweneed:

Page 7: ML-03 Logistic Regression - IITKGP

AndrewNg

SigmoidfunctionLogisticfunction

LogisticRegressionModelWant

0

Ausefulproperty:easytocomputedifferentialatanypoint

Page 8: ML-03 Logistic Regression - IITKGP

AndrewNg

InterpretationofHypothesisOutput

=estimatedprobabilitythaty=1oninputx

Tellpatientthat70%chanceoftumorbeingmalignant

Example:If

“probabilitythaty=1,givenx,parameterized by”

Page 9: ML-03 Logistic Regression - IITKGP

AndrewNg

Logisticregression

Supposepredict““if

predict““if

Page 10: ML-03 Logistic Regression - IITKGP

AndrewNg

Logisticregression

Supposepredict““if

predict““if

When𝛩Tx ≥0

When𝛩Tx <0

Page 11: ML-03 Logistic Regression - IITKGP

AndrewNg

Separatingtwoclassesofpoints• Weareattemptingtoseparatetwogivensets/classesofpoints

• Separatetworegionsofthefeaturespace• ConceptofDecisionBoundary• Findingagooddecisionboundary=>learnappropriatevaluesfortheparameters𝛩

Page 12: ML-03 Logistic Regression - IITKGP

AndrewNg

x1

x2

DecisionBoundary

1 2 3

1

2

3

Page 13: ML-03 Logistic Regression - IITKGP

AndrewNg

x1

x2

DecisionBoundary

1 2 3

1

2

3

Predictif

Howtogettheparametervalues– willbediscussedsoon

Page 14: ML-03 Logistic Regression - IITKGP

AndrewNg

Non-linear decisionboundaries

x1

x2

1-1

-1

1

Wecanlearnmorecomplexdecisionboundarieswhere thehypothesisfunctioncontainshigherorderterms.

(rememberpolynomialregression)

Page 15: ML-03 Logistic Regression - IITKGP

AndrewNg

Non-linear decisionboundaries

x1

x2

Predictif

1-1

-1

1

Howtogettheparametervalues– willbediscussedsoon

Page 16: ML-03 Logistic Regression - IITKGP

CostfunctionforLogisticRegression

Howtogettheparameter values?

Page 17: ML-03 Logistic Regression - IITKGP

AndrewNg

Trainingset:

Howtochooseparameters?

mexamples

Page 18: ML-03 Logistic Regression - IITKGP

AndrewNg

Costfunction

Linearregression:

Howeverthiscostfunction isnon-convexforthehypothesisoflogisticregression.

Squarederrorcostfunction:

Page 19: ML-03 Logistic Regression - IITKGP

AndrewNg

Logisticregressioncostfunction

Cost

Page 20: ML-03 Logistic Regression - IITKGP

AndrewNg

Logisticregressioncostfunction

Page 21: ML-03 Logistic Regression - IITKGP

AndrewNg

Logisticregressioncostfunction

Page 22: ML-03 Logistic Regression - IITKGP

AndrewNg

Logisticregressioncostfunction

Tofitparameters:Thiscostfunctionisconvex

Page 23: ML-03 Logistic Regression - IITKGP

AndrewNg

GradientDescent

Want:Repeat

(simultaneouslyupdateall)

Page 24: ML-03 Logistic Regression - IITKGP

AndrewNg

GradientDescent

Want:

(simultaneouslyupdateall)

Repeat

Algorithmlooksidenticaltolinearregression,butthehypothesisfunctionisdifferentforlogisticregression.

Page 25: ML-03 Logistic Regression - IITKGP

AndrewNg

Thuswecangradientdescenttolearnparametervalues,andhencecomputeforanewinput:

Output

Tomakeapredictiongivennew :

=estimatedprobabilitythaty=1oninputx

Page 26: ML-03 Logistic Regression - IITKGP

AndrewNg

Howtousetheestimatedprobability?• Refrainingfromclassifyingunlessconfident• Rankingitems• Multi-classclassification

Page 27: ML-03 Logistic Regression - IITKGP

Multi-classclassification:onevs.all

Page 28: ML-03 Logistic Regression - IITKGP

AndrewNg

Multiclassclassification

Newsarticletagging:Politics,Sports,Movies,Religion,…

Medicaldiagnosis:Notill,Cold,Flu,Fever

Weather:Sunny,Cloudy,Rain,Snow

Page 29: ML-03 Logistic Regression - IITKGP

AndrewNg

x1

x2

x1

x2

Binaryclassification: Multi-classclassification:

Page 30: ML-03 Logistic Regression - IITKGP

AndrewNg

x1

x2

One-vs-all(one-vs-rest):

Class1:Class2:Class3:

x1

x2

x1

x2

x1

x2

Page 31: ML-03 Logistic Regression - IITKGP

AndrewNg

One-vs-all

Trainalogisticregressionclassifierforeachclasstopredicttheprobabilitythat.

Onanewinput,tomakeaprediction,picktheclassthatmaximizes

Page 32: ML-03 Logistic Regression - IITKGP

AndrewNg

AdvancedOptimization algorithms (notpartofthiscourse)

Optimizationalgorithms:- Gradientdescent- Conjugategradient- BFGS- L-BFGS

Advantagesoftheotheralgorithms:- Noneedtomanuallypicklearningrate- Oftenconvergesfasterthangradientdescent

Disadvantages:- Morecomplex