> For the complete documentation index, see [llms.txt](https://sisyphus.gitbook.io/project/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://sisyphus.gitbook.io/project/machine-learning/logistic-regression.md).

# Logistic Regression

It is a **classification** algorithm used to estimate discrete values ( binary values like 0/1, yes/no, true/false ) based on given set of independent variable(s). In simple words, it predicts the probability of occurrence of an event by fitting data to a logit function.

Hence, **logistic regression** is also known as **logit regression**. Since, it predicts the probability, its output values lies between 0 and 1 (as expected).

Let’s say your friend gives you a puzzle to solve. There are only 2 outcome scenarios – either you solve it or you don’t.Coming to the math, the log odds of the outcome is modeled as a linear combination of the predictor variables.

```
odds= p/ (1-p) = probability of event occurrence / probability of not 
\event occurrence
ln(odds) = ln(p/(1-p))
logit(p) = ln(p/(1-p)) = b0+b1X1+b2X2+b3X3....+bkXk
```

Above, p is the probability of presence of the characteristic of interest. *It chooses parameters that maximize the likelihood of observing the sample values rather than that minimize the sum of squared errors (like in ordinary regression).*

Now, you may ask, why take a log? For the sake of simplicity, let’s just say that this is one of the best mathematical way to replicate a step function.

### What if we just use linear regression on discrete classes?

![](/files/-LTJo8VzqWjUQQuFZNub)

**Pink**: a workable case

**Blue**: a problematic case

### **Linear Regression vs Logistic Regression output value range:**

![](/files/-LTJp0y49Z5-8vGnEsm8)

### Logistic Function

![](/files/-LTKy3wQgcYgg-b688kg)

A **logistic function** or **logistic curve** is a common "S" shape ([sigmoid curve](https://en.wikipedia.org/wiki/Sigmoid_function)), with equation:

&#x20;                                                 <img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/6f42e36c949c94189976ae00853af9a1b618e099" alt="{\displaystyle f(x)={\frac {L}{1+e^{-k(x-x_{0})}}}}" data-size="original">

where

* e = the [natural logarithm](https://en.wikipedia.org/wiki/Natural_logarithm) base (also known as [Euler's number](https://en.wikipedia.org/wiki/E_\(mathematical_constant\))),
* x0 = the x-value of the sigmoid's midpoint,
* L = the curve's maximum value, and
* k = the steepness of the curve.

&#x20;                                 <img src="/files/-LOBiefxMZ86TONKvtbu" alt="" data-size="original">

![](https://wikimedia.org/api/rest_v1/media/math/render/svg/c9ccf5c48fc073952bbbafe5e2a11d4eaddb90cb)

### Not use least square cost function since it would be non-convex

![](/files/-LTK-fVzeMbzqPsnyfTf)

### Two class cross entropy loss

h(x) is a binary class logistic function and the output of two classes are already normalized.

![](/files/-LTK-t9v0a3sQUkjFk5H)

![](/files/-LTK05pK7B0YztSObxqx)

### Multi-Class one vs all

![](/files/-LTK2PJjpT5qfIpLNBEX)

### Multinomial Logistic Regression - SoftMax

<div align="center"><img src="/files/-LGH_1zvfJXzh6IBv8dZ" alt="What is Cross Entropy Loss"></div>

![Differences](/files/-LGHa7nGk0U1Ch6QxT1i)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://sisyphus.gitbook.io/project/machine-learning/logistic-regression.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
