Logistic regression is a supervised learning classification algorithm used to predict the probability of a target variable. It's generally used where the target variable is Binary or Dichotomous. Follow along and check the most common 23 Logistic Regression Interview Questions and Answers you may face on your next Data Science and Machine Learning interview.
In Logistic regression models, we are modeling the probability that an input (X) belongs to the default class (Y=1), that is to say:
where the P(X) values are given by the logistic function,
The β0 and β1 values are estimated during the training stage using maximum-likelihood estimation or gradient descent. Once we have it, we can make predictions by simply putting numbers into the logistic regression equation and calculating a result.
For example, let's consider that we have a model that can predict whether a person is male or female based on their height, such as if P(X) ≥ 0.5 the person is male, and if P(X) < 0.5 then is female.
During the training stage we obtain β0 = -100 and β1 = 0.6, and we want to evaluate what's the probability that a person with a height of 150cm is male, so with that intention we compute:
Given that logistic regression solves a classification task, we can use directly this value to predict that the person is a female.
Logistic regression can be used in classification problems where the output or dependent variable is categorical or binary. However, in order to implement logistic regression correctly, the dataset must also satisfy the following properties:
logit of the outcome and each predictor variable. The logit function is given as logit(p) = log(p/(1-p)), where p is the probability of the outcome.When all the requirements above are satisfied, logistic regression can be used.
Although the task we are targeting in logistic regression is a classification, logistic regression does not actually individually classify things for you: it just gives you probabilities (or log odds ratios in the logit form).
The only way logistic regression can actually classify stuff is if you apply a rule to the probability output. For example, you may round probabilities greater than or equal to 50% to 1, and probabilities less than 50% to 0, and that’s your classification.
For Logistic Regression, outliers can have an unusually large effect on the estimate of logistic regression coefficients. It will find a linear boundary if it exists to accommodate the outliers. To solve the problem of outliers, sometimes a sigmoid function is used in logistic regression.
For SVM, outliers can make the decision boundary deviate severely from the optimal hyperplane. One way for SVM to get around the problem is to intrduce slack variables. There is a penalty involved with using slack variables, and how SVM handles outliers depends on how this penalty is imposed.
The logistic model is trained through the logistic function, defined as:
where x is the input data, w is the weight vector, y is the output label, and P(y) is the probability that the output label belongs to one class. If for some input we got P(y) > 0.5, then the predicted output is 1, and otherwise would be 0.
The training is based in estimate the w vector. For this, in each training instance we use Stochastic Gradient Descent to calculate a prediction using some initial values of the coefficients, and then calculate new coefficient values based on the error in the previous prediction. The process is repeated for a fixed number of iterations or until the model is accurate enough or cannot be made any more accurate.
0 and 1, it gives the probability of the outcome.Logistic regression can be seen as a transformation from linear regression to logistic regression using the logistic function, also known as the sigmoid function or S(x):
Given the linear model:
If we apply the sigmoid function to the above equation it results:
where p is the probability and it takes values between 0 and 1. If we now apply the logit function to p, it results:
The equation above represents the logistic regression. It fits a logistic curve to set of data where the dependent variable can only take the values 0 and 1.
The previous transformation can be illustrated in the following figure:
Also, what should we do to fix the problem of each decision boundary?
What can we infer:
What can we do to fix the problem:
Softmax function:
1.Sigmoid function:
1.It is required for the independent and dependent variables to be linear for linear regression models, but the independent and dependent variables are not required to have a linear relationship in logistic functions.
The Linear Regression models assume that the error terms are normally distributed (bell-shaped graph) whereas there are no error terms in Logistic Regression because it is assumed to follow a Bernoulli distribution.
0 and 1. A linear regression may have an output that can go beyond 0 and 1.A model is considered linear if the transformation of features that is used to calculate the prediction is a linear combination of the features. Although Logistic Regression uses Sigmoid function which is a nonlinear function, the model is a generalized linear model because the outcome always depends on the sum of the inputs and parameters.
i.e the logit of the estimated probability response is a linear function of the predictors parameters.
Prepare for AI developer and engineer interviews with 19 answered OpenClaw questions covering Gateway architecture, channels, agent workspaces, memory, MCP, model failover, multi-agent routing, security, sandboxing, approvals, and remote operations....
Prepare for AI agent developer interviews with 15 Model Context Protocol (MCP) questions covering tools, resources, prompts, JSON-RPC, transports, roots, sampling, security, and practical MCP server design....
Amazone runs the internet as we know it. Amazon Web Services (AWS) offers a comprehensive suite of machine learning (ML) services that cater to various needs and expertise levels. Follow along and learn the 23 most common AWS machine-learning intervi...