SlideShare a Scribd company logo
1 of 20
Download to read offline
Logistic Regression
Data science and AI Certification Course
Visit: Learnbay.co
Introduction
Logistic Regression is a classification algorithm. It is used to predict a binary
outcome (1 / 0, Yes / No, True / False) given a set of independent variables.
You can also think of logistic regression as a special case of linear regression
when the outcome variable is categorical, where we are using log of odds as
dependent variable.
In simple words, it predicts the probability of occurrence of an event by fitting
data to a logitfunction.
Visit: Learnbay.co
Logit/Sigmoid function
The logistic function, also called the sigmoid function was developed by
statisticians to describe properties of population growth in ecology, rising
quickly and maxing out at the carrying capacity of the environment. It’s an
S-shaped curve that can take any real-valued number and map it into a value
between 0 and 1, but never exactly at those limits.
1 / (1 + e^-value)
Visit: Learnbay.co
Where e is the base of the natural logarithms (Euler’s number or the EXP()
function in your spreadsheet) and value is the actual numerical value that you
want to transform. Below is a plot of the numbers between -5 and 5
transformed into the range 0 and 1 using the logistic function.
Visit: Learnbay.co
Logit function
Visit: Learnbay.co
Generalized Linear Model
g(E(y)) = α + βx1 +γx2
Here, g() is the linkfunction,
E(y) is the expectation oftarget variable and
α + βx1 + γx2 is the linear predictor ( α,β,γ to be predicted).
The role of link function is to ‘link’ the expectation of y to linear predictor.
Visit: Learnbay.co
Problem statement
We are provided a sample of 1000 customers. We need to predict the
probability whether a customer will buy (y) a particular magazine or not.
As you can see, we’ve a categorical outcomevariable, we’ll use logistic
regression
g(y) = βo +β(Age) ----(a)
Visit: Learnbay.co
Derivation
In logistic regression, we are only concerned about the probability of outcome
dependent variable ( success or failure). As described above, g() is the link
function. This function is established using two things: Probability of
Success(p) and Probability of Failure(1-p). p should meet following criteria:
1. It must always be positive (since p >= 0)
2. It must always be less than equals to 1 (since p <= 1)
Visit: Learnbay.co
Since probability must always be positive, we’ll put the linear equation in
exponential form. For any value of slope and dependent variable, exponent of
this equation will never benegative.
p = exp(βo + β(Age)) = e^(βo+ β(Age)) ------- (b)
Visit: Learnbay.co
To make the probability less than 1, we must divide p by a number greater than
p. This can simply be doneby:
p = exp(βo + β(Age)) / exp(βo + β(Age)) + 1 = e^(βo + β(Age)) / e^(βo + β
(Age)) + 1 ----- (c)
Using (a), (b) and (c), we can redefine the probability as:
Visit: Learnbay.co
p = e^y/ 1 + e^y --- (d)
where p is the probability of success. This (d) is the Logit Function
If p is the probability of success, 1-p will be the probability of failure which can
be written as:
q = 1 - p = 1 - (e^y/ 1+ e^y) --- (e)
Visit: Learnbay.co
On dividing, (d) / (e), we get,
After taking log on both side, we get,
log(p/1-p) is the link function. Logarithmic transformation on the outcome
variable allows us to model a non-linear association in a linear way. Visit: Learnbay.co
Final equation
After substituting value of y,we’llget:
This is the equation used in Logistic Regression. Here (p/1-p) is the odd ratio. A typical logistic model
plot is shown next. You can see probability never goes below 0 and above 1.
Visit: Learnbay.co
Logit function graph
Visit: Learnbay.co
Logistic regression models the probability of the default class (e.g. the first class).
For example, if we are modeling people’s Gender as male or female from their height, then the first
class could be male and the logistic regression model could be written as the probability of male given
a person’s height, or moreformally:
P(Gender=male|height)
Written another way, we are modeling the probability that an input (X) belongs to the default class
(Y=1), we can write this formallyas:
P(X) = P(Y=1|X)
Visit: Learnbay.co
ln(p(X) / 1 – p(X)) = b0 + b1 * X
This equation is useful because we can see that the calculation of the output
on the right is linear again (just like linear regression), and the input on the left
is a log of the probability of the default class.
This ratio on the left is called the odds of the default class
Visit: Learnbay.co
Learning Logistic model
The coefficients (Beta values b) of the logistic regression algorithm must be
estimated from your training data. This is done using maximum-likelihood
estimation.
Maximum-likelihood estimation is a common learning algorithm used by a
variety of machine learning algorithms, although it does make assumptions
about the distribution of your data
Visit: Learnbay.co
The best coefficients would result in a model that would predict a value very
close to 1 (e.g. male) for the default class and a value very close to 0 (e.g.
female) for the other class. The intuition for maximum-likelihood for logistic
regression is that a search procedure seeks values for the coefficients (Beta
values) that minimize the error in the probabilities predicted by the model to
those in the data (e.g. probability of 1 if the data is the primary class).
Visit: Learnbay.co
Let’s say we have a model that can predict whether a person is male or female based on
their height (completely fictitious). Given a height of 150cm is the person male or female.
We have learned the coefficients of b0 = -100 and b1 = 0.6. Using the equation above we
can calculate the probability of male given a height of 150cm or more formally
P(male|height=150). We will use EXP() for e, because that is what you can use if you type
this example into yourspreadsheet:
y = e^(b0 + b1*X) / (1 + e^(b0 + b1*X))
y = exp(-100 + 0.6*150) / (1 + EXP(-100 + 0.6*X))
y = 0.0000453978687
Visit: Learnbay.co
we can snap the probabilities to a binary class value, for example:
1 if p(male) <0.5
2 if p(male) >=0.5
Visit: Learnbay.co

More Related Content

Similar to Logistic regression, machine learning algorithms

Linear logisticregression
Linear logisticregressionLinear logisticregression
Linear logisticregressionkongara
 
Lecture 3.1_ Logistic Regression.pptx
Lecture 3.1_ Logistic Regression.pptxLecture 3.1_ Logistic Regression.pptx
Lecture 3.1_ Logistic Regression.pptxajondaree
 
Logistic Regression.pptx
Logistic Regression.pptxLogistic Regression.pptx
Logistic Regression.pptxMuskaan194530
 
CS229 Machine Learning Lecture Notes
CS229 Machine Learning Lecture NotesCS229 Machine Learning Lecture Notes
CS229 Machine Learning Lecture NotesEric Conner
 
Logistic Regression in machine learning.docx
Logistic Regression in machine learning.docxLogistic Regression in machine learning.docx
Logistic Regression in machine learning.docxAbhaBansal8
 
Ai_Project_report
Ai_Project_reportAi_Project_report
Ai_Project_reportRavi Gupta
 
Machine learning (1)
Machine learning (1)Machine learning (1)
Machine learning (1)NYversity
 
Logistic regression
Logistic regressionLogistic regression
Logistic regressionRupak Roy
 
Logistic regression
Logistic regressionLogistic regression
Logistic regressionAyurdata
 
Detail Study of the concept of Regression model.pptx
Detail Study of the concept of  Regression model.pptxDetail Study of the concept of  Regression model.pptx
Detail Study of the concept of Regression model.pptxtruptikulkarni2066
 
Machine learning (4)
Machine learning (4)Machine learning (4)
Machine learning (4)NYversity
 
Supervised Learning.pdf
Supervised Learning.pdfSupervised Learning.pdf
Supervised Learning.pdfgadissaassefa
 
Machine learning
Machine learningMachine learning
Machine learningShreyas G S
 
Logistic regression.ppt
Logistic regression.pptLogistic regression.ppt
Logistic regression.pptBalaChowdappa1
 
Understanding Blackbox Prediction via Influence Functions
Understanding Blackbox Prediction via Influence FunctionsUnderstanding Blackbox Prediction via Influence Functions
Understanding Blackbox Prediction via Influence FunctionsSEMINARGROOT
 

Similar to Logistic regression, machine learning algorithms (20)

Linear logisticregression
Linear logisticregressionLinear logisticregression
Linear logisticregression
 
Lecture 3.1_ Logistic Regression.pptx
Lecture 3.1_ Logistic Regression.pptxLecture 3.1_ Logistic Regression.pptx
Lecture 3.1_ Logistic Regression.pptx
 
3ml.pdf
3ml.pdf3ml.pdf
3ml.pdf
 
Logistic Regression.pptx
Logistic Regression.pptxLogistic Regression.pptx
Logistic Regression.pptx
 
Machine Learning
Machine LearningMachine Learning
Machine Learning
 
CS229 Machine Learning Lecture Notes
CS229 Machine Learning Lecture NotesCS229 Machine Learning Lecture Notes
CS229 Machine Learning Lecture Notes
 
Logistics regression
Logistics regressionLogistics regression
Logistics regression
 
Logistic.pdf
Logistic.pdfLogistic.pdf
Logistic.pdf
 
Logistic Regression in machine learning.docx
Logistic Regression in machine learning.docxLogistic Regression in machine learning.docx
Logistic Regression in machine learning.docx
 
Ai_Project_report
Ai_Project_reportAi_Project_report
Ai_Project_report
 
Machine learning (1)
Machine learning (1)Machine learning (1)
Machine learning (1)
 
Logistic regression
Logistic regressionLogistic regression
Logistic regression
 
Logistic regression
Logistic regressionLogistic regression
Logistic regression
 
Detail Study of the concept of Regression model.pptx
Detail Study of the concept of  Regression model.pptxDetail Study of the concept of  Regression model.pptx
Detail Study of the concept of Regression model.pptx
 
Machine learning (4)
Machine learning (4)Machine learning (4)
Machine learning (4)
 
Supervised Learning.pdf
Supervised Learning.pdfSupervised Learning.pdf
Supervised Learning.pdf
 
Machine learning
Machine learningMachine learning
Machine learning
 
Overview of Java
Overview of Java Overview of Java
Overview of Java
 
Logistic regression.ppt
Logistic regression.pptLogistic regression.ppt
Logistic regression.ppt
 
Understanding Blackbox Prediction via Influence Functions
Understanding Blackbox Prediction via Influence FunctionsUnderstanding Blackbox Prediction via Influence Functions
Understanding Blackbox Prediction via Influence Functions
 

More from Learnbay Datascience

Artificial Intelligence- Neural Networks
Artificial Intelligence- Neural NetworksArtificial Intelligence- Neural Networks
Artificial Intelligence- Neural NetworksLearnbay Datascience
 
Artificial intelligence - expert systems
 Artificial intelligence - expert systems Artificial intelligence - expert systems
Artificial intelligence - expert systemsLearnbay Datascience
 
Artificial intelligence - research areas
Artificial intelligence - research areasArtificial intelligence - research areas
Artificial intelligence - research areasLearnbay Datascience
 
Artificial intelligence intelligent systems
Artificial intelligence   intelligent systemsArtificial intelligence   intelligent systems
Artificial intelligence intelligent systemsLearnbay Datascience
 

More from Learnbay Datascience (20)

Top data science projects
Top data science projectsTop data science projects
Top data science projects
 
Python my SQL - create table
Python my SQL - create tablePython my SQL - create table
Python my SQL - create table
 
Python my SQL - create database
Python my SQL - create databasePython my SQL - create database
Python my SQL - create database
 
Python my sql database connection
Python my sql   database connectionPython my sql   database connection
Python my sql database connection
 
Python - mySOL
Python - mySOLPython - mySOL
Python - mySOL
 
AI - Issues and Terminology
AI - Issues and TerminologyAI - Issues and Terminology
AI - Issues and Terminology
 
AI - Fuzzy Logic Systems
AI - Fuzzy Logic SystemsAI - Fuzzy Logic Systems
AI - Fuzzy Logic Systems
 
AI - working of an ns
AI - working of an nsAI - working of an ns
AI - working of an ns
 
Artificial Intelligence- Neural Networks
Artificial Intelligence- Neural NetworksArtificial Intelligence- Neural Networks
Artificial Intelligence- Neural Networks
 
AI - Robotics
AI - RoboticsAI - Robotics
AI - Robotics
 
Applications of expert system
Applications of expert systemApplications of expert system
Applications of expert system
 
Components of expert systems
Components of expert systemsComponents of expert systems
Components of expert systems
 
Artificial intelligence - expert systems
 Artificial intelligence - expert systems Artificial intelligence - expert systems
Artificial intelligence - expert systems
 
AI - natural language processing
AI - natural language processingAI - natural language processing
AI - natural language processing
 
Ai popular search algorithms
Ai   popular search algorithmsAi   popular search algorithms
Ai popular search algorithms
 
AI - Agents & Environments
AI - Agents & EnvironmentsAI - Agents & Environments
AI - Agents & Environments
 
Artificial intelligence - research areas
Artificial intelligence - research areasArtificial intelligence - research areas
Artificial intelligence - research areas
 
Artificial intelligence composed
Artificial intelligence composedArtificial intelligence composed
Artificial intelligence composed
 
Artificial intelligence intelligent systems
Artificial intelligence   intelligent systemsArtificial intelligence   intelligent systems
Artificial intelligence intelligent systems
 
Applications of ai
Applications of aiApplications of ai
Applications of ai
 

Recently uploaded

MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptxPoojaSen20
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfUmakantAnnand
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersChitralekhaTherkar
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 

Recently uploaded (20)

MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptx
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of Powders
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 

Logistic regression, machine learning algorithms

  • 1. Logistic Regression Data science and AI Certification Course Visit: Learnbay.co
  • 2. Introduction Logistic Regression is a classification algorithm. It is used to predict a binary outcome (1 / 0, Yes / No, True / False) given a set of independent variables. You can also think of logistic regression as a special case of linear regression when the outcome variable is categorical, where we are using log of odds as dependent variable. In simple words, it predicts the probability of occurrence of an event by fitting data to a logitfunction. Visit: Learnbay.co
  • 3. Logit/Sigmoid function The logistic function, also called the sigmoid function was developed by statisticians to describe properties of population growth in ecology, rising quickly and maxing out at the carrying capacity of the environment. It’s an S-shaped curve that can take any real-valued number and map it into a value between 0 and 1, but never exactly at those limits. 1 / (1 + e^-value) Visit: Learnbay.co
  • 4. Where e is the base of the natural logarithms (Euler’s number or the EXP() function in your spreadsheet) and value is the actual numerical value that you want to transform. Below is a plot of the numbers between -5 and 5 transformed into the range 0 and 1 using the logistic function. Visit: Learnbay.co
  • 6. Generalized Linear Model g(E(y)) = α + βx1 +γx2 Here, g() is the linkfunction, E(y) is the expectation oftarget variable and α + βx1 + γx2 is the linear predictor ( α,β,γ to be predicted). The role of link function is to ‘link’ the expectation of y to linear predictor. Visit: Learnbay.co
  • 7. Problem statement We are provided a sample of 1000 customers. We need to predict the probability whether a customer will buy (y) a particular magazine or not. As you can see, we’ve a categorical outcomevariable, we’ll use logistic regression g(y) = βo +β(Age) ----(a) Visit: Learnbay.co
  • 8. Derivation In logistic regression, we are only concerned about the probability of outcome dependent variable ( success or failure). As described above, g() is the link function. This function is established using two things: Probability of Success(p) and Probability of Failure(1-p). p should meet following criteria: 1. It must always be positive (since p >= 0) 2. It must always be less than equals to 1 (since p <= 1) Visit: Learnbay.co
  • 9. Since probability must always be positive, we’ll put the linear equation in exponential form. For any value of slope and dependent variable, exponent of this equation will never benegative. p = exp(βo + β(Age)) = e^(βo+ β(Age)) ------- (b) Visit: Learnbay.co
  • 10. To make the probability less than 1, we must divide p by a number greater than p. This can simply be doneby: p = exp(βo + β(Age)) / exp(βo + β(Age)) + 1 = e^(βo + β(Age)) / e^(βo + β (Age)) + 1 ----- (c) Using (a), (b) and (c), we can redefine the probability as: Visit: Learnbay.co
  • 11. p = e^y/ 1 + e^y --- (d) where p is the probability of success. This (d) is the Logit Function If p is the probability of success, 1-p will be the probability of failure which can be written as: q = 1 - p = 1 - (e^y/ 1+ e^y) --- (e) Visit: Learnbay.co
  • 12. On dividing, (d) / (e), we get, After taking log on both side, we get, log(p/1-p) is the link function. Logarithmic transformation on the outcome variable allows us to model a non-linear association in a linear way. Visit: Learnbay.co
  • 13. Final equation After substituting value of y,we’llget: This is the equation used in Logistic Regression. Here (p/1-p) is the odd ratio. A typical logistic model plot is shown next. You can see probability never goes below 0 and above 1. Visit: Learnbay.co
  • 15. Logistic regression models the probability of the default class (e.g. the first class). For example, if we are modeling people’s Gender as male or female from their height, then the first class could be male and the logistic regression model could be written as the probability of male given a person’s height, or moreformally: P(Gender=male|height) Written another way, we are modeling the probability that an input (X) belongs to the default class (Y=1), we can write this formallyas: P(X) = P(Y=1|X) Visit: Learnbay.co
  • 16. ln(p(X) / 1 – p(X)) = b0 + b1 * X This equation is useful because we can see that the calculation of the output on the right is linear again (just like linear regression), and the input on the left is a log of the probability of the default class. This ratio on the left is called the odds of the default class Visit: Learnbay.co
  • 17. Learning Logistic model The coefficients (Beta values b) of the logistic regression algorithm must be estimated from your training data. This is done using maximum-likelihood estimation. Maximum-likelihood estimation is a common learning algorithm used by a variety of machine learning algorithms, although it does make assumptions about the distribution of your data Visit: Learnbay.co
  • 18. The best coefficients would result in a model that would predict a value very close to 1 (e.g. male) for the default class and a value very close to 0 (e.g. female) for the other class. The intuition for maximum-likelihood for logistic regression is that a search procedure seeks values for the coefficients (Beta values) that minimize the error in the probabilities predicted by the model to those in the data (e.g. probability of 1 if the data is the primary class). Visit: Learnbay.co
  • 19. Let’s say we have a model that can predict whether a person is male or female based on their height (completely fictitious). Given a height of 150cm is the person male or female. We have learned the coefficients of b0 = -100 and b1 = 0.6. Using the equation above we can calculate the probability of male given a height of 150cm or more formally P(male|height=150). We will use EXP() for e, because that is what you can use if you type this example into yourspreadsheet: y = e^(b0 + b1*X) / (1 + e^(b0 + b1*X)) y = exp(-100 + 0.6*150) / (1 + EXP(-100 + 0.6*X)) y = 0.0000453978687 Visit: Learnbay.co
  • 20. we can snap the probabilities to a binary class value, for example: 1 if p(male) <0.5 2 if p(male) >=0.5 Visit: Learnbay.co