SlideShare une entreprise Scribd logo
1  sur  24
Logistic Regression
The Logistic Regression is a regression model in which
the response variable (dependent variable) has
categorical values such as True/False or 0/1. It
actually measures the probability of a binary
response as the value of response variable based on
the mathematical equation relating it with the
predictor
Logistic regression estimates the probability of an
event occurring, such as voted or didn't vote, based
on a given dataset of independent variables.
Since the outcome is a probability, the dependent
variable is bounded between 0 and 1. variables.
• Linear : When there is a linear relationship
between independent and dependent
variables is known as linear regression
• Logistic: When the independent variable is
categorical in nature it is known as logistic
regression
• Polynomial: When the power of the
independent variables is more than 1 then it is
referred as polynomial regression
Why Logistic Regression
• Whenever the outcome of the dependent variable
(y) is discrete like0/1 then we use logistic regression
• In linear regression y ‘s value is in a range but in our
case Y value is discrete, ie, the value will either be 0
or 1.
• Logistic regression
• It gives a probability . What are the chances that Y
will become 1.
• Ex: Basketball( 10 scored, the threshhold value is
0.8, if it is less than to 0.5, Y value is above threshold
then Y is 1 otherwise Y is 0)
• The general mathematical equation for logistic
regression is −
• y = 1/(1+e^-(a+b1x1+b2x2+b3x3+...))
• Following is the description of the parameters
used −
• y is the response variable.
• x is the predictor variable.
• a and b are the coefficients which are numeric
constants.
• The function used to create the regression model
is the glm() function.
• Syntax
• The basic syntax for glm() function in logistic
regression is −
• glm(formula,data,family) Following is the
description of the parameters used −
• formula is the symbol presenting the relationship
between the variables.
• data is the data set giving the values of these
variables.
• family is R object to specify the details of the
model. It's value is binomial for logistic regression.
Example
• The in-built data set "mtcars" describes different
models of a car with their various engine
specifications. In "mtcars" data set, the
transmission mode (automatic or manual) is
described by the column am which is a binary
value (0 or 1). We can create a logistic regression
model between the columns "am" and 3 other
columns - hp, wt and cyl.
• # Select some columns form mtcars.
• input <- mtcars[,c("am","cyl","hp","wt")]
print(head(input))
• When we execute the above code, it produces
the following result −
• am cyl hp wt
• Mazda RX4 1 6 110 2.620
• Mazda RX4 Wag 1 6 110 2.875
• Datsun 710 1 4 93 2.320
• Hornet 4 Drive 0 6 110 3.215
• Hornet Sportabout 0 8 175 3.440
• Valiant 0 6 105 3.460
• Create Regression Model
• We use the glm() function to create the
regression model and get its summary for
analysis.
• input <- mtcars[,c("am","cyl","hp","wt")]
am.data = glm(formula = am ~ cyl + hp + wt,
data = input, family = binomial)
print(summary(am.data))
Advantages
• Logistic regression is easier to implement, interpret,
and very efficient to train.
• It makes no assumptions about distributions of
classes in feature space.
• It can easily extend to multiple classes(multinomial
regression) and a natural probabilistic view of class
predictions.
• It not only provides a measure of how appropriate a
predictor(coefficient size)is, but also its direction of
association (positive or negative).
• It is very fast at classifying unknown records.
Uses of Logistic Regression
• Classification Problems
it is important category of problems in which a decision
makers classifies the customers into two or more
categories
• Discrete choice Model
It estimates the probability about customers who
select a particular brand over several brands are
available
• Probability
It measures the probability of the occurrence of any
event. It find out the probability of an event
Generalized Linear Model
• Generalized Linear Model (GLiM, or GLM) is an
advanced statistical modelling technique
formulated by John Nelder and Robert
Wedderburn in 1972.
• It is an umbrella term that encompasses many
other models, which allows the response
variable y to have an error distribution other
than a normal distribution.
• The models include Linear Regression, Logistic
Regression, and Poisson Regression.
Why GLM?
• Linear Regression model is not suitable if,
• The relationship between X and y is not linear. There exists
some non-linear relationship between them. For example,
y increases exponentially as X increases.
• Variance of errors in y (commonly called as
Homoscedasticity in Linear Regression), is not constant,
and varies with X.
• Response variable is not continuous, but
discrete/categorical.
• Linear Regression assumes normal distribution of the
response variable, which can only be applied on a
continuous data.
• If we try to build a linear regression model on a
discrete/binary y variable, then the linear regression
model predicts negative values for the corresponding
response variable, which is inappropriate.
Assumptions of GLM
• Similar to Linear Regression Model, there are some basic
assumptions for Generalized Linear Models as well. Most
of the assumptions are similar to Linear Regression
models, while some of the assumptions of Linear
Regression are modified.
• Data should be independent and random (Each Random
variable has the same probability distribution).
• The response variable y does not need to be normally
distributed, but the distribution is from an exponential
family (e.g. binomial, Poisson, multinomial, normal)
• The original response variable need not have a linear
relationship with the independent variables, but the
transformed response variable (through the link function)
is linearly dependent on the independent variables
Binomial Logistic Regression
• A (often referred to simply as logistic regression), predicts
the probability that an observation falls into one of two
categories of a dichotomous dependent variable based
on one or more independent variables that can be either
continuous or categorical.
• For example, you could use binomial logistic regression to
understand whether exam performance can be predicted
based on revision time, test anxiety and lecture
attendance (i.e., where the dependent variable is "exam
performance", measured on a dichotomous scale –
"passed" or "failed" – and you have three independent
variables: "revision time", "test anxiety" and "lecture
attendance").
Logistic Function
• It is a function that estimates various parameters
and check whether they are statistically significant
and influence the probability of an event
• logit function
• One of the big assumptions of linear models is that
the residuals are normally distributed.
• This doesn’t mean that Y, the response variable, has
to also be normally distributed, but it does have to
be continuous, unbounded and measured on an
interval or ratio scale.
• Unfortunately, categorical response variables are
none of these.
• The Logit Link Function
• A link function is simply a function of the mean of the
response variable Y that we use as the response instead
of Y itself.
• All that means is when Y is categorical, we use the logit of
Y as the response in our regression equation instead of
just Y:
• The logit function is the natural log of the odds that Y
equals one of the categories. For mathematical simplicity,
we’re going to assume Y has only two categories and code
them as 0 and 1.
• This is entirely arbitrary–we could have used any
numbers. But these make the math work out nicely, so
let’s stick with them.
• P is defined as the probability that Y=1. So for example,
those Xs could be specific risk factors, like age, high blood
pressure, and cholesterol level, and P would be the
probability that a patient develops heart disease.
Optim function
• The function optim provides algorithms for general-
purpose optimisations and the documentation is perfectly
reasonable, but I remember that it took me a little while to
get my head around how to pass data and parameters to
optim
• should return a scalar result. A function to return the
gradient for the "BFGS" , "CG" and "L-BFGS-B" methods. If
it is NULL , a finite-difference approximation will be used.
For the "SANN" method it specifies a function to generate
a new candidate point.
• optim(par, fn, data, ...)
• where:
• par: Initial values for the parameters to be optimized over
• fn: A function to be minimized or maximized
• data: The name of the object in R that contains the data
• df <- data.frame(x=c(1, 3, 3, 5, 6, 7, 9, 12), y=c(4,
5, 8, 6, 9, 10, 13, 17))
• #define function to minimize residual sum of
squares min_residuals <- function(data, par) {
with(data, sum((par[1] + par[2] * x - y)^2)) }
• #find coefficients of linear regression model
optim(par=c(0, 1), fn=min_residuals, data=df)
• $par
• $value
• $counts
• $convergence
• $message
Maximum likelihood Estimator
• We can use MLE in order to get more robust
parameter estimates. Thus, MLE can be
defined as a method for estimating population
parameters (such as the mean and variance
for Normal, rate (lambda) for Poisson, etc.)
from sample data such that the probability
(likelihood) of obtaining the observed data is
maximized.
• n <- 1000 x <- rnorm(n,2,3) # with mean = 2, sd = 3
• he essential part of MLE is to specify the likelihood
function. In R, you can easily use “dnorm” to obtain
the density, and specify “log = TRUE”. Then, the
objective to minimize the negative sum of log
likelihood function, which is equivalent to maximize
the positive sum.
• LL <- function(beta, sigma){ R = dnorm(x, beta,
sigma, log = TRUE) -sum(R) }Following that, the
parameters to be estimated can be passed to the
“mle2” function, available in package “bbmle”, which
uses the optimization technique to find the solution.
• library(bbmle). (true parameter)
• fit_norm <- mle2(LL, start = list(beta = 0, sigma = 1),
lower = c(-Inf, 0), upper = c(Inf, Inf), method = 'L-
BFGS-B')
Logistical Regression.pptx
Logistical Regression.pptx
Logistical Regression.pptx

Contenu connexe

Tendances

Logistic regression with SPSS
Logistic regression with SPSSLogistic regression with SPSS
Logistic regression with SPSSLNIPE
 
Regression (Linear Regression and Logistic Regression) by Akanksha Bali
Regression (Linear Regression and Logistic Regression) by Akanksha BaliRegression (Linear Regression and Logistic Regression) by Akanksha Bali
Regression (Linear Regression and Logistic Regression) by Akanksha BaliAkanksha Bali
 
Estimation and hypothesis testing 1 (graduate statistics2)
Estimation and hypothesis testing 1 (graduate statistics2)Estimation and hypothesis testing 1 (graduate statistics2)
Estimation and hypothesis testing 1 (graduate statistics2)Harve Abella
 
Multinomial logisticregression basicrelationships
Multinomial logisticregression basicrelationshipsMultinomial logisticregression basicrelationships
Multinomial logisticregression basicrelationshipsAnirudha si
 
Probability Distribution
Probability DistributionProbability Distribution
Probability DistributionShahnawazAli81
 
Regression analysis
Regression analysisRegression analysis
Regression analysisRavi shankar
 
Lesson 2 stationary_time_series
Lesson 2 stationary_time_seriesLesson 2 stationary_time_series
Lesson 2 stationary_time_seriesankit_ppt
 
Logistic regression with SPSS examples
Logistic regression with SPSS examplesLogistic regression with SPSS examples
Logistic regression with SPSS examplesGaurav Kamboj
 
Introduction to Generalized Linear Models
Introduction to Generalized Linear ModelsIntroduction to Generalized Linear Models
Introduction to Generalized Linear Modelsrichardchandler
 
Logistic regression
Logistic regressionLogistic regression
Logistic regressionsaba khan
 
Linear Regression With R
Linear Regression With RLinear Regression With R
Linear Regression With REdureka!
 
Multiple linear regression
Multiple linear regressionMultiple linear regression
Multiple linear regressionAshek Farabi
 
Simple Linear Regression: Step-By-Step
Simple Linear Regression: Step-By-StepSimple Linear Regression: Step-By-Step
Simple Linear Regression: Step-By-StepDan Wellisch
 
Regression analysis
Regression analysisRegression analysis
Regression analysissaba khan
 
Regression analysis and its type
Regression analysis and its typeRegression analysis and its type
Regression analysis and its typeEkta Bafna
 

Tendances (20)

Logistic regression with SPSS
Logistic regression with SPSSLogistic regression with SPSS
Logistic regression with SPSS
 
Regression (Linear Regression and Logistic Regression) by Akanksha Bali
Regression (Linear Regression and Logistic Regression) by Akanksha BaliRegression (Linear Regression and Logistic Regression) by Akanksha Bali
Regression (Linear Regression and Logistic Regression) by Akanksha Bali
 
Estimation and hypothesis testing 1 (graduate statistics2)
Estimation and hypothesis testing 1 (graduate statistics2)Estimation and hypothesis testing 1 (graduate statistics2)
Estimation and hypothesis testing 1 (graduate statistics2)
 
Multinomial logisticregression basicrelationships
Multinomial logisticregression basicrelationshipsMultinomial logisticregression basicrelationships
Multinomial logisticregression basicrelationships
 
Probability Distribution
Probability DistributionProbability Distribution
Probability Distribution
 
Logistic regression
Logistic regressionLogistic regression
Logistic regression
 
Simple linear regression
Simple linear regressionSimple linear regression
Simple linear regression
 
Regression analysis
Regression analysisRegression analysis
Regression analysis
 
Lesson 2 stationary_time_series
Lesson 2 stationary_time_seriesLesson 2 stationary_time_series
Lesson 2 stationary_time_series
 
Logistic regression with SPSS examples
Logistic regression with SPSS examplesLogistic regression with SPSS examples
Logistic regression with SPSS examples
 
Introduction to Generalized Linear Models
Introduction to Generalized Linear ModelsIntroduction to Generalized Linear Models
Introduction to Generalized Linear Models
 
Ridge regression
Ridge regressionRidge regression
Ridge regression
 
Logistic regression
Logistic regressionLogistic regression
Logistic regression
 
Binary Logistic Regression
Binary Logistic RegressionBinary Logistic Regression
Binary Logistic Regression
 
Linear Regression With R
Linear Regression With RLinear Regression With R
Linear Regression With R
 
Multiple linear regression
Multiple linear regressionMultiple linear regression
Multiple linear regression
 
Simple Linear Regression: Step-By-Step
Simple Linear Regression: Step-By-StepSimple Linear Regression: Step-By-Step
Simple Linear Regression: Step-By-Step
 
Regression analysis
Regression analysisRegression analysis
Regression analysis
 
Correlation and Simple Regression
Correlation  and Simple RegressionCorrelation  and Simple Regression
Correlation and Simple Regression
 
Regression analysis and its type
Regression analysis and its typeRegression analysis and its type
Regression analysis and its type
 

Similaire à Logistical Regression.pptx

7. logistics regression using spss
7. logistics regression using spss7. logistics regression using spss
7. logistics regression using spssDr Nisha Arora
 
Logistic Regression in machine learning.docx
Logistic Regression in machine learning.docxLogistic Regression in machine learning.docx
Logistic Regression in machine learning.docxAbhaBansal8
 
Regression Analysis.pptx
Regression Analysis.pptxRegression Analysis.pptx
Regression Analysis.pptxarsh260174
 
Regression Analysis Techniques.pptx
Regression Analysis Techniques.pptxRegression Analysis Techniques.pptx
Regression Analysis Techniques.pptxYutaItadori
 
Logistic Regression.pptx
Logistic Regression.pptxLogistic Regression.pptx
Logistic Regression.pptxssuser2624f71
 
Logistic Regression power point presentation.pptx
Logistic Regression power point presentation.pptxLogistic Regression power point presentation.pptx
Logistic Regression power point presentation.pptxharshasawa2003
 
Supervised Learning.pdf
Supervised Learning.pdfSupervised Learning.pdf
Supervised Learning.pdfgadissaassefa
 
Logistic regression - one of the key regression tools in experimental research
Logistic regression - one of the key regression tools in experimental researchLogistic regression - one of the key regression tools in experimental research
Logistic regression - one of the key regression tools in experimental researchAdrian Olszewski
 
A presentation for Multiple linear regression.ppt
A presentation for Multiple linear regression.pptA presentation for Multiple linear regression.ppt
A presentation for Multiple linear regression.pptvigia41
 
Lecture 3.1_ Logistic Regression.pptx
Lecture 3.1_ Logistic Regression.pptxLecture 3.1_ Logistic Regression.pptx
Lecture 3.1_ Logistic Regression.pptxajondaree
 
Regression analysis made easy
Regression analysis made easyRegression analysis made easy
Regression analysis made easyWeam Banjar
 
Final generalized linear modeling by idrees waris iugc
Final generalized linear modeling by idrees waris iugcFinal generalized linear modeling by idrees waris iugc
Final generalized linear modeling by idrees waris iugcId'rees Waris
 
Unit 3 – AIML.pptx
Unit 3 – AIML.pptxUnit 3 – AIML.pptx
Unit 3 – AIML.pptxhiblooms
 
Ch_17_Wooldridge_6e_PPT_Updated.pdf.pdf
Ch_17_Wooldridge_6e_PPT_Updated.pdf.pdfCh_17_Wooldridge_6e_PPT_Updated.pdf.pdf
Ch_17_Wooldridge_6e_PPT_Updated.pdf.pdfROBERTOENRIQUEGARCAA1
 
Multinomial Logistic Regression.pdf
Multinomial Logistic Regression.pdfMultinomial Logistic Regression.pdf
Multinomial Logistic Regression.pdfAlemAyahu
 

Similaire à Logistical Regression.pptx (20)

GLMs.pptx
GLMs.pptxGLMs.pptx
GLMs.pptx
 
7. logistics regression using spss
7. logistics regression using spss7. logistics regression using spss
7. logistics regression using spss
 
Logistic Regression in machine learning.docx
Logistic Regression in machine learning.docxLogistic Regression in machine learning.docx
Logistic Regression in machine learning.docx
 
Regression Analysis.pptx
Regression Analysis.pptxRegression Analysis.pptx
Regression Analysis.pptx
 
Regression Analysis Techniques.pptx
Regression Analysis Techniques.pptxRegression Analysis Techniques.pptx
Regression Analysis Techniques.pptx
 
Logistic Regression.pptx
Logistic Regression.pptxLogistic Regression.pptx
Logistic Regression.pptx
 
Logistic Regression power point presentation.pptx
Logistic Regression power point presentation.pptxLogistic Regression power point presentation.pptx
Logistic Regression power point presentation.pptx
 
Supervised Learning.pdf
Supervised Learning.pdfSupervised Learning.pdf
Supervised Learning.pdf
 
Logistic regression - one of the key regression tools in experimental research
Logistic regression - one of the key regression tools in experimental researchLogistic regression - one of the key regression tools in experimental research
Logistic regression - one of the key regression tools in experimental research
 
A presentation for Multiple linear regression.ppt
A presentation for Multiple linear regression.pptA presentation for Multiple linear regression.ppt
A presentation for Multiple linear regression.ppt
 
Lecture 4
Lecture 4Lecture 4
Lecture 4
 
Lecture 3.1_ Logistic Regression.pptx
Lecture 3.1_ Logistic Regression.pptxLecture 3.1_ Logistic Regression.pptx
Lecture 3.1_ Logistic Regression.pptx
 
Regression
Regression Regression
Regression
 
Ai saturdays presentation
Ai saturdays presentationAi saturdays presentation
Ai saturdays presentation
 
Regression analysis made easy
Regression analysis made easyRegression analysis made easy
Regression analysis made easy
 
classification.pptx
classification.pptxclassification.pptx
classification.pptx
 
Final generalized linear modeling by idrees waris iugc
Final generalized linear modeling by idrees waris iugcFinal generalized linear modeling by idrees waris iugc
Final generalized linear modeling by idrees waris iugc
 
Unit 3 – AIML.pptx
Unit 3 – AIML.pptxUnit 3 – AIML.pptx
Unit 3 – AIML.pptx
 
Ch_17_Wooldridge_6e_PPT_Updated.pdf.pdf
Ch_17_Wooldridge_6e_PPT_Updated.pdf.pdfCh_17_Wooldridge_6e_PPT_Updated.pdf.pdf
Ch_17_Wooldridge_6e_PPT_Updated.pdf.pdf
 
Multinomial Logistic Regression.pdf
Multinomial Logistic Regression.pdfMultinomial Logistic Regression.pdf
Multinomial Logistic Regression.pdf
 

Plus de Ramakrishna Reddy Bijjam

Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
Arrays to arrays and pointers with arrays.pptx
Arrays to arrays and pointers with arrays.pptxArrays to arrays and pointers with arrays.pptx
Arrays to arrays and pointers with arrays.pptxRamakrishna Reddy Bijjam
 
Python With MongoDB in advanced Python.pptx
Python With MongoDB in advanced Python.pptxPython With MongoDB in advanced Python.pptx
Python With MongoDB in advanced Python.pptxRamakrishna Reddy Bijjam
 
Pointers and single &multi dimentionalarrays.pptx
Pointers and single &multi dimentionalarrays.pptxPointers and single &multi dimentionalarrays.pptx
Pointers and single &multi dimentionalarrays.pptxRamakrishna Reddy Bijjam
 
Certinity Factor and Dempster-shafer theory .pptx
Certinity Factor and Dempster-shafer theory .pptxCertinity Factor and Dempster-shafer theory .pptx
Certinity Factor and Dempster-shafer theory .pptxRamakrishna Reddy Bijjam
 
Auxiliary Memory in computer Architecture.pptx
Auxiliary Memory in computer Architecture.pptxAuxiliary Memory in computer Architecture.pptx
Auxiliary Memory in computer Architecture.pptxRamakrishna Reddy Bijjam
 

Plus de Ramakrishna Reddy Bijjam (20)

Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Arrays to arrays and pointers with arrays.pptx
Arrays to arrays and pointers with arrays.pptxArrays to arrays and pointers with arrays.pptx
Arrays to arrays and pointers with arrays.pptx
 
Auxiliary, Cache and Virtual memory.pptx
Auxiliary, Cache and Virtual memory.pptxAuxiliary, Cache and Virtual memory.pptx
Auxiliary, Cache and Virtual memory.pptx
 
Python With MongoDB in advanced Python.pptx
Python With MongoDB in advanced Python.pptxPython With MongoDB in advanced Python.pptx
Python With MongoDB in advanced Python.pptx
 
Pointers and single &multi dimentionalarrays.pptx
Pointers and single &multi dimentionalarrays.pptxPointers and single &multi dimentionalarrays.pptx
Pointers and single &multi dimentionalarrays.pptx
 
Certinity Factor and Dempster-shafer theory .pptx
Certinity Factor and Dempster-shafer theory .pptxCertinity Factor and Dempster-shafer theory .pptx
Certinity Factor and Dempster-shafer theory .pptx
 
Auxiliary Memory in computer Architecture.pptx
Auxiliary Memory in computer Architecture.pptxAuxiliary Memory in computer Architecture.pptx
Auxiliary Memory in computer Architecture.pptx
 
Random Forest Decision Tree.pptx
Random Forest Decision Tree.pptxRandom Forest Decision Tree.pptx
Random Forest Decision Tree.pptx
 
K Means Clustering in ML.pptx
K Means Clustering in ML.pptxK Means Clustering in ML.pptx
K Means Clustering in ML.pptx
 
Pandas.pptx
Pandas.pptxPandas.pptx
Pandas.pptx
 
Python With MongoDB.pptx
Python With MongoDB.pptxPython With MongoDB.pptx
Python With MongoDB.pptx
 
Python with MySql.pptx
Python with MySql.pptxPython with MySql.pptx
Python with MySql.pptx
 
PYTHON PROGRAMMING NOTES RKREDDY.pdf
PYTHON PROGRAMMING NOTES RKREDDY.pdfPYTHON PROGRAMMING NOTES RKREDDY.pdf
PYTHON PROGRAMMING NOTES RKREDDY.pdf
 
BInary file Operations.pptx
BInary file Operations.pptxBInary file Operations.pptx
BInary file Operations.pptx
 
Data Science in Python.pptx
Data Science in Python.pptxData Science in Python.pptx
Data Science in Python.pptx
 
CSV JSON and XML files in Python.pptx
CSV JSON and XML files in Python.pptxCSV JSON and XML files in Python.pptx
CSV JSON and XML files in Python.pptx
 
HTML files in python.pptx
HTML files in python.pptxHTML files in python.pptx
HTML files in python.pptx
 
Regular Expressions in Python.pptx
Regular Expressions in Python.pptxRegular Expressions in Python.pptx
Regular Expressions in Python.pptx
 
datareprersentation 1.pptx
datareprersentation 1.pptxdatareprersentation 1.pptx
datareprersentation 1.pptx
 
Apriori.pptx
Apriori.pptxApriori.pptx
Apriori.pptx
 

Dernier

Halmar dropshipping via API with DroFx
Halmar  dropshipping  via API with DroFxHalmar  dropshipping  via API with DroFx
Halmar dropshipping via API with DroFxolyaivanovalion
 
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...amitlee9823
 
Probability Grade 10 Third Quarter Lessons
Probability Grade 10 Third Quarter LessonsProbability Grade 10 Third Quarter Lessons
Probability Grade 10 Third Quarter LessonsJoseMangaJr1
 
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...Valters Lauzums
 
Midocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFxMidocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFxolyaivanovalion
 
April 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's AnalysisApril 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's Analysismanisha194592
 
Accredited-Transport-Cooperatives-Jan-2021-Web.pdf
Accredited-Transport-Cooperatives-Jan-2021-Web.pdfAccredited-Transport-Cooperatives-Jan-2021-Web.pdf
Accredited-Transport-Cooperatives-Jan-2021-Web.pdfadriantubila
 
Call Girls In Attibele ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Attibele ☎ 7737669865 🥵 Book Your One night StandCall Girls In Attibele ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Attibele ☎ 7737669865 🥵 Book Your One night Standamitlee9823
 
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...amitlee9823
 
BigBuy dropshipping via API with DroFx.pptx
BigBuy dropshipping via API with DroFx.pptxBigBuy dropshipping via API with DroFx.pptx
BigBuy dropshipping via API with DroFx.pptxolyaivanovalion
 
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service BangaloreCall Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangaloreamitlee9823
 
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...amitlee9823
 
Capstone Project on IBM Data Analytics Program
Capstone Project on IBM Data Analytics ProgramCapstone Project on IBM Data Analytics Program
Capstone Project on IBM Data Analytics ProgramMoniSankarHazra
 
Generative AI on Enterprise Cloud with NiFi and Milvus
Generative AI on Enterprise Cloud with NiFi and MilvusGenerative AI on Enterprise Cloud with NiFi and Milvus
Generative AI on Enterprise Cloud with NiFi and MilvusTimothy Spann
 
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 nightCheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 nightDelhi Call girls
 
Discover Why Less is More in B2B Research
Discover Why Less is More in B2B ResearchDiscover Why Less is More in B2B Research
Discover Why Less is More in B2B Researchmichael115558
 

Dernier (20)

Halmar dropshipping via API with DroFx
Halmar  dropshipping  via API with DroFxHalmar  dropshipping  via API with DroFx
Halmar dropshipping via API with DroFx
 
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
 
CHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Probability Grade 10 Third Quarter Lessons
Probability Grade 10 Third Quarter LessonsProbability Grade 10 Third Quarter Lessons
Probability Grade 10 Third Quarter Lessons
 
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
 
Midocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFxMidocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFx
 
April 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's AnalysisApril 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's Analysis
 
Accredited-Transport-Cooperatives-Jan-2021-Web.pdf
Accredited-Transport-Cooperatives-Jan-2021-Web.pdfAccredited-Transport-Cooperatives-Jan-2021-Web.pdf
Accredited-Transport-Cooperatives-Jan-2021-Web.pdf
 
Call Girls In Attibele ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Attibele ☎ 7737669865 🥵 Book Your One night StandCall Girls In Attibele ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Attibele ☎ 7737669865 🥵 Book Your One night Stand
 
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
 
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts ServiceCall Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
 
BigBuy dropshipping via API with DroFx.pptx
BigBuy dropshipping via API with DroFx.pptxBigBuy dropshipping via API with DroFx.pptx
BigBuy dropshipping via API with DroFx.pptx
 
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service BangaloreCall Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
 
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
 
Capstone Project on IBM Data Analytics Program
Capstone Project on IBM Data Analytics ProgramCapstone Project on IBM Data Analytics Program
Capstone Project on IBM Data Analytics Program
 
Generative AI on Enterprise Cloud with NiFi and Milvus
Generative AI on Enterprise Cloud with NiFi and MilvusGenerative AI on Enterprise Cloud with NiFi and Milvus
Generative AI on Enterprise Cloud with NiFi and Milvus
 
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 nightCheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
 
Discover Why Less is More in B2B Research
Discover Why Less is More in B2B ResearchDiscover Why Less is More in B2B Research
Discover Why Less is More in B2B Research
 
Predicting Loan Approval: A Data Science Project
Predicting Loan Approval: A Data Science ProjectPredicting Loan Approval: A Data Science Project
Predicting Loan Approval: A Data Science Project
 

Logistical Regression.pptx

  • 1. Logistic Regression The Logistic Regression is a regression model in which the response variable (dependent variable) has categorical values such as True/False or 0/1. It actually measures the probability of a binary response as the value of response variable based on the mathematical equation relating it with the predictor Logistic regression estimates the probability of an event occurring, such as voted or didn't vote, based on a given dataset of independent variables. Since the outcome is a probability, the dependent variable is bounded between 0 and 1. variables.
  • 2. • Linear : When there is a linear relationship between independent and dependent variables is known as linear regression • Logistic: When the independent variable is categorical in nature it is known as logistic regression • Polynomial: When the power of the independent variables is more than 1 then it is referred as polynomial regression
  • 3.
  • 4. Why Logistic Regression • Whenever the outcome of the dependent variable (y) is discrete like0/1 then we use logistic regression • In linear regression y ‘s value is in a range but in our case Y value is discrete, ie, the value will either be 0 or 1. • Logistic regression • It gives a probability . What are the chances that Y will become 1. • Ex: Basketball( 10 scored, the threshhold value is 0.8, if it is less than to 0.5, Y value is above threshold then Y is 1 otherwise Y is 0)
  • 5. • The general mathematical equation for logistic regression is − • y = 1/(1+e^-(a+b1x1+b2x2+b3x3+...)) • Following is the description of the parameters used − • y is the response variable. • x is the predictor variable. • a and b are the coefficients which are numeric constants. • The function used to create the regression model is the glm() function.
  • 6. • Syntax • The basic syntax for glm() function in logistic regression is − • glm(formula,data,family) Following is the description of the parameters used − • formula is the symbol presenting the relationship between the variables. • data is the data set giving the values of these variables. • family is R object to specify the details of the model. It's value is binomial for logistic regression.
  • 7. Example • The in-built data set "mtcars" describes different models of a car with their various engine specifications. In "mtcars" data set, the transmission mode (automatic or manual) is described by the column am which is a binary value (0 or 1). We can create a logistic regression model between the columns "am" and 3 other columns - hp, wt and cyl. • # Select some columns form mtcars. • input <- mtcars[,c("am","cyl","hp","wt")] print(head(input))
  • 8. • When we execute the above code, it produces the following result − • am cyl hp wt • Mazda RX4 1 6 110 2.620 • Mazda RX4 Wag 1 6 110 2.875 • Datsun 710 1 4 93 2.320 • Hornet 4 Drive 0 6 110 3.215 • Hornet Sportabout 0 8 175 3.440 • Valiant 0 6 105 3.460
  • 9. • Create Regression Model • We use the glm() function to create the regression model and get its summary for analysis. • input <- mtcars[,c("am","cyl","hp","wt")] am.data = glm(formula = am ~ cyl + hp + wt, data = input, family = binomial) print(summary(am.data))
  • 10. Advantages • Logistic regression is easier to implement, interpret, and very efficient to train. • It makes no assumptions about distributions of classes in feature space. • It can easily extend to multiple classes(multinomial regression) and a natural probabilistic view of class predictions. • It not only provides a measure of how appropriate a predictor(coefficient size)is, but also its direction of association (positive or negative). • It is very fast at classifying unknown records.
  • 11. Uses of Logistic Regression • Classification Problems it is important category of problems in which a decision makers classifies the customers into two or more categories • Discrete choice Model It estimates the probability about customers who select a particular brand over several brands are available • Probability It measures the probability of the occurrence of any event. It find out the probability of an event
  • 12. Generalized Linear Model • Generalized Linear Model (GLiM, or GLM) is an advanced statistical modelling technique formulated by John Nelder and Robert Wedderburn in 1972. • It is an umbrella term that encompasses many other models, which allows the response variable y to have an error distribution other than a normal distribution. • The models include Linear Regression, Logistic Regression, and Poisson Regression.
  • 13. Why GLM? • Linear Regression model is not suitable if, • The relationship between X and y is not linear. There exists some non-linear relationship between them. For example, y increases exponentially as X increases. • Variance of errors in y (commonly called as Homoscedasticity in Linear Regression), is not constant, and varies with X. • Response variable is not continuous, but discrete/categorical. • Linear Regression assumes normal distribution of the response variable, which can only be applied on a continuous data. • If we try to build a linear regression model on a discrete/binary y variable, then the linear regression model predicts negative values for the corresponding response variable, which is inappropriate.
  • 14. Assumptions of GLM • Similar to Linear Regression Model, there are some basic assumptions for Generalized Linear Models as well. Most of the assumptions are similar to Linear Regression models, while some of the assumptions of Linear Regression are modified. • Data should be independent and random (Each Random variable has the same probability distribution). • The response variable y does not need to be normally distributed, but the distribution is from an exponential family (e.g. binomial, Poisson, multinomial, normal) • The original response variable need not have a linear relationship with the independent variables, but the transformed response variable (through the link function) is linearly dependent on the independent variables
  • 15. Binomial Logistic Regression • A (often referred to simply as logistic regression), predicts the probability that an observation falls into one of two categories of a dichotomous dependent variable based on one or more independent variables that can be either continuous or categorical. • For example, you could use binomial logistic regression to understand whether exam performance can be predicted based on revision time, test anxiety and lecture attendance (i.e., where the dependent variable is "exam performance", measured on a dichotomous scale – "passed" or "failed" – and you have three independent variables: "revision time", "test anxiety" and "lecture attendance").
  • 16. Logistic Function • It is a function that estimates various parameters and check whether they are statistically significant and influence the probability of an event • logit function • One of the big assumptions of linear models is that the residuals are normally distributed. • This doesn’t mean that Y, the response variable, has to also be normally distributed, but it does have to be continuous, unbounded and measured on an interval or ratio scale. • Unfortunately, categorical response variables are none of these.
  • 17. • The Logit Link Function • A link function is simply a function of the mean of the response variable Y that we use as the response instead of Y itself. • All that means is when Y is categorical, we use the logit of Y as the response in our regression equation instead of just Y: • The logit function is the natural log of the odds that Y equals one of the categories. For mathematical simplicity, we’re going to assume Y has only two categories and code them as 0 and 1. • This is entirely arbitrary–we could have used any numbers. But these make the math work out nicely, so let’s stick with them. • P is defined as the probability that Y=1. So for example, those Xs could be specific risk factors, like age, high blood pressure, and cholesterol level, and P would be the probability that a patient develops heart disease.
  • 18. Optim function • The function optim provides algorithms for general- purpose optimisations and the documentation is perfectly reasonable, but I remember that it took me a little while to get my head around how to pass data and parameters to optim • should return a scalar result. A function to return the gradient for the "BFGS" , "CG" and "L-BFGS-B" methods. If it is NULL , a finite-difference approximation will be used. For the "SANN" method it specifies a function to generate a new candidate point. • optim(par, fn, data, ...) • where: • par: Initial values for the parameters to be optimized over • fn: A function to be minimized or maximized • data: The name of the object in R that contains the data
  • 19. • df <- data.frame(x=c(1, 3, 3, 5, 6, 7, 9, 12), y=c(4, 5, 8, 6, 9, 10, 13, 17)) • #define function to minimize residual sum of squares min_residuals <- function(data, par) { with(data, sum((par[1] + par[2] * x - y)^2)) } • #find coefficients of linear regression model optim(par=c(0, 1), fn=min_residuals, data=df) • $par • $value • $counts • $convergence • $message
  • 20. Maximum likelihood Estimator • We can use MLE in order to get more robust parameter estimates. Thus, MLE can be defined as a method for estimating population parameters (such as the mean and variance for Normal, rate (lambda) for Poisson, etc.) from sample data such that the probability (likelihood) of obtaining the observed data is maximized.
  • 21. • n <- 1000 x <- rnorm(n,2,3) # with mean = 2, sd = 3 • he essential part of MLE is to specify the likelihood function. In R, you can easily use “dnorm” to obtain the density, and specify “log = TRUE”. Then, the objective to minimize the negative sum of log likelihood function, which is equivalent to maximize the positive sum. • LL <- function(beta, sigma){ R = dnorm(x, beta, sigma, log = TRUE) -sum(R) }Following that, the parameters to be estimated can be passed to the “mle2” function, available in package “bbmle”, which uses the optimization technique to find the solution. • library(bbmle). (true parameter) • fit_norm <- mle2(LL, start = list(beta = 0, sigma = 1), lower = c(-Inf, 0), upper = c(Inf, Inf), method = 'L- BFGS-B')