II. Logistic Regression & Optimization


Advanced Machine Learning

     

Lecturer: Dr. HAS Sothea

1 Binary Logistic Regression

1.1 Binary Logistic Regression

Model setting

x1 x2 y
-0.752759 2.704286 1
1.935603 -0.838856 0
  • Objective: Given input \(\text{x}_i\in\mathbb{R}^d\), classify if \(y\in\{0,1\}\).
  • Main idea: classify \(\Leftrightarrow\) identify decision boundary.
  • Assumption: Boundary is linear.

Logistic Regression Model

  • Given input \(\text{x}_i\), the chance that it belongs to class \(1\) is given by \[\mathbb{P}(Y_i=1|X=\text{x}_i)=\sigma(\color{blue}{\beta_0}+\sum_{j=1}^d\color{blue}{\beta_j}x_{ij}),\] where \(\color{blue}{\beta_0,\beta_1,\dots,\beta_d}\in\mathbb{R}\) are the key parameters to be estiamted from the data, and \(\sigma(z)=1/(1+e^{-z}),\forall z\in\mathbb{R}\).

Model intuition

  • Ex: Given \(\text{x}_0=[\text{h}_0,\text{w}_0]\in\mathbb{R}^2,\) for any candidate parameter \(\color{blue}{\vec{\beta}=[\beta_0,\beta_1,\beta_2]}\), \[\color{green}{z_0}=\color{blue}{\beta_0}+\color{blue}{\beta_1}\text{h}_0+\color{blue}{\beta_2}\text{w}_0\text{ is the relative distance from }\text{x}_0\to\text{ Boundary (B)}.\]
  • That’s to say that
    • \(\color{green}{z_0}>0\Leftrightarrow \text{x}_0\) is above the boundary.
    • \(|\color{green}{z_0}|\) is large \(\Leftrightarrow\) \(\text{x}_0\) is far from the bounday.
  • A good boundary should be such that:
    • Large \(|\color{green}{z_0}|\Rightarrow\) “certain about its class”.
    • Small \(|\color{green}{z_0}|\Rightarrow\) “less certain about its class”.

Model intuition

  • A good boundary should should be:
    • Large \(|\color{green}{z_0}|\Rightarrow\) “certain about its class”.
    • Small \(|\color{green}{z_0}|\Rightarrow\) “less certain about its class”.
  • Sigmoid function: \(\sigma:\mathbb{R}\to (0,1)\)

\[\color{green}{z}\mapsto\sigma(\color{green}{z})=\frac{1}{1+\exp(-\color{green}{z})}.\]

Key ideas

  • \(\color{green}{z_0}=\color{blue}{\beta_0}+\text{x}_0^T\color{blue}{\vec{\beta}}\) is the relative distance of \(\text{x}_0\) w.r.t (B).
  • Sigmoid converts this relative distance into probability.

Example

  • Suppose \(\color{blue}{(\beta_0,\beta_1,\beta_2)=(-1, -1, 2)}\), compute \(p(\color{blue}{1}|\text{x})\):
x1 x2 y
2.489186 -0.779048 0
-2.572868 -1.086146 1
2.767143 2.432104 0
  • Compute relative distance \(z_i=\color{blue}{\beta_0}+\text{x}_i^T\color{blue}{\vec{\beta}}\), then \(p(1|\text{x}_i)\) \[\begin{align*}z_1&=-1-1(2.489186)+2(-0.779048)\\ &=-5.047282<0\\ \Rightarrow p(1|\text{x}_1)&=\sigma(z_1)=1/(1+e^{-(-5.047282)})=\color{red}{0.00641}.\\ \\ z_2&=-1-1(-2.572868)+2(-1.086146)\\ &=-0.599424<0\\ \Rightarrow p(1|\text{x}_2)&=\sigma(z_2)=1/(1+e^{-(-0.599424)})=\color{red}{0.354483}.\\ \\ z_3&=-1-1(2.767143)+2(2.432104)\\ &=1.097065 > 0\\ \Rightarrow p(1|\text{x}_3)&=\sigma(z_3)=1/(1+e^{-1.097065})=\color{blue}{0.749788}.\end{align*}\]

  • Interpretation: \(\text{x}_1,\text{x}_2\) are located below the line \((B):-1-x_1+2x_2\) as \(z_1,z_2<0\) and are predicted to be in class \(\color{red}{0}\). On the other hand, \(\text{x}_3\) is located above the line (\(z_3>0\)) and is predicted to be in class \(\color{blue}{1}\).

  • Question: Now, how do we find the best key parameter \(\color{blue}{\beta_0,\dots,\beta_d}\)?

Conditional likelihood \(\to\) Cross-entropy

  • Data: \({\cal D}=\{(\text{x}_1,y_1),...,(\text{x}_n,y_n)\}\subset\mathbb{R}^d\times \{0,1\}\).
  • Objective: search for \(\color{blue}{\beta_0}\in\mathbb{R},\color{blue}{\vec{\beta}}\in\mathbb{R}^d\) such that the model is best aligned with the data \({\cal D}\): \[p(y_i|\text{x}_i)\text{ is large for all }i\in\{1,\dots,n\}.\]
  • Conditional Likelihood Function: If the data are iid, one has \[\begin{align*}{L}(\color{blue}{\beta_0},\color{blue}{\vec{\beta}})&=\mathbb{P}(Y_1=y_1,\dots,Y_n=y_n|X_1=\text{x}_1,\dots,X_n=\text{x}_n)\\ &=\prod_{i=1}^np(y_i|\text{x}_i)\\ &=\prod_{i=1}^n\Big[p(1|\text{x}_i)\Big]^{y_i}\Big[p(0|\text{x}_i)\Big]^{1-y_i}\\ &=\prod_{i=1}^n\Big[\sigma(\color{blue}{\beta_0}+\text{x}_i^T\color{blue}{\vec{\beta}})\Big]^{y_i}\Big[(1-\sigma(\color{blue}{\beta_0}+\text{x}_i^T\color{blue}{\vec{\beta}}))\Big]^{1-y_i}. \end{align*}\]

  • Cross-entropy: \(\text{CEn}(\color{blue}{\vec{\beta}})=-\sum_{i=1}^n\Big[y_i\log[\sigma(\color{blue}{\beta_0}+\text{x}_i^T\color{blue}{\vec{\beta}})]+(1-y_i)\log[(1-\sigma(\color{blue}{\beta_0}+\text{x}_i^T\color{blue}{\vec{\beta}}))]\Big]\).

Conditional likelihood \(\to\) Cross-entropy

  • Cross-entropy: \[\text{CEn}(\color{blue}{\vec{\beta}})=-\sum_{i=1}^n\Big[y_i\log[\sigma(\color{blue}{\beta_0}+\text{x}_i^T\color{blue}{\vec{\beta}})]+(1-y_i)\log[(1-\sigma(\color{blue}{\beta_0}+\text{x}_i^T\color{blue}{\vec{\beta}}))]\Big].\]
  • It’s also known as log-loss or logistic loss.

Conditional likelihood \(\to\) Cross-entropy

  • We search for coefficient \(\color{blue}{\vec{\beta}}=[\color{blue}{\beta_0,\dots,\beta_d}]\) minimizing \[\boxed{\text{CEn}(\color{blue}{\vec{\beta}})=-\sum_{i=1}^n\Big[y_i\log[\sigma(\color{blue}{\beta_0}+\text{x}_i^T\color{blue}{\vec{\beta}})]+(1-y_i)\log[(1-\sigma(\color{blue}{\beta_0}+\text{x}_i^T\color{blue}{\vec{\beta}}))]\Big].}\]

  • 😭 Unfortunately, such minimizer values \((\color{blue}{\widehat{\beta}_0,\widehat{\vec{\beta}}})\) CANNOT be analytically computed.

  • 😊 Fortunately, it can be numerically approximated!

  • We can use optimization algorithms such as Gradient Descent Algorithm to estimate the best \(\color{blue}{\hat{\beta}}\).

  • This is the next step!

Summary Logistic Regression Model

  • Main model: \(p(1|\text{x})=1/(1+e^{-\color{green}{z}})=1/(1+e^{-(\color{blue}{\beta_0}+\text{x}^T\color{blue}{\vec{\beta}})})\).
    • Boundary decision is Linear defined by the coefficients \(\color{blue}{\beta_0}\) and \(\color{blue}{\vec{\beta}}\).
    • Probability of being in each class depends on the relative distance of that point to the boundary.
    • Works well when classes are linearly separable.
  • Objective: Search for \(\color{blue}{\beta_0}\) and \(\color{blue}{\vec{\beta}}\) that minimizes the Cross-entropy.

Coef. \({\color{blue}{\beta}}\) Interpretation

  • In binary classification, \(\color{blue}{\textbf{odds ratio}}=\frac{\mathbb{P}(y_i=1\mid X=\text{x}_i)}{\mathbb{P}(y_i=0\mid X=\text{x}_i)}=\frac{p_i}{1-p_i}\).

1.2 Example: Exam Passing

  • Suppose we model whether a student passes an exam: \[\log\left(\frac{p}{1-p}\right)= {\color{blue}{\beta_0}} + {\color{blue}{\beta_1}}\text{StudyHours}+{\color{blue}{\beta_2}}\text{Attendance}\]

  • If \({\color{blue}{\beta_1}} = 0.50\) then

    • Log-odds: A 1-hour increase in study time increases the log-odds of passing by \(\boxed{0.50}\), holding Attendance constant.
    • Odds ratio: Convert the coefficient to an odds ratio: \(e^{0.50}\approx 1.65\), meaning that 1-hour increase in study time multiplies the odds of passing by 1.65.
    • Percentage interpretation: \((1.65-1)\times100\%\approx65\%\) → The odds of passing increase by \(\approx\) 65% for each additional hour of study.
  • Important: This is a 65% increase in odds, not a 65%-point increase in probability.

2 Optimization: GD & SGD

2.1 Optimization algorithm

Gradient

  • If \(\ell:\mathbb{R}^d\to\mathbb{R}, y=\ell(x_1,...,x_d)\) be a real-valued function of \(d\) real variables. For any point \(a\in\mathbb{R}^d\), the gradient of \(L\) at point \(a\) is a \(d\)-dimensional vector defined by \[\nabla \ell(a)=\begin{bmatrix}\frac{\partial \ell}{\partial x_1}(a)\\ \vdots\\ \frac{\partial \ell}{\partial x_d}(a)\end{bmatrix}.\]
  • It is the direction (from the point \(a\)) with the fastest increasing rate of the function \(\ell\).
  • Ex: \(f(x,y)=0.1x^4+0.5y^2\). Compute \(\nabla f(1,-1)\).
    • One has \(\frac{\partial f}{\partial x}=0.4x^3\) and \(\frac{\partial f}{\partial y}=y\).
    • Therefore, \(\nabla f(1,-1)=(0.4,-1).\)
    • Meaning: from point \((1,-1)\), function \(f\) increases fastest along the direction \((0.4, -1)\).
  • Around 1847, Augustin-Louis Cauchy used this to propose a genius algorithm in optimization!

Gradient: Direction of steepest ascent

  • Gradient is a vector pointing to the steepest ascent of the function.

2.2 Optimization algorithm

Gradient Descent Algorithm (GD)

  • Key Idea: At any \({\color{blue}{\theta_0}}\in\mathbb{R}^d\), and if \(\ell\) is differentiable, one can approximate \(\ell\) around \({\color{blue}{\theta_0}}\) by \[\forall \color{red}{h}\in\mathbb{R}^d (\text{small}):\ell(\color{blue}{\theta_0}+\color{red}{h})\approx \ell(\color{blue}{\theta_0})+\nabla \ell({\color{blue}{\theta_0}})^T\color{red}{h}.\]
  • If \(\color{red}{h}=-\color{green}{\eta}\nabla \ell({\color{blue}{\theta_0}})\) for some \(\color{green}{\eta}>0\), we have: \(\ell(\color{blue}{\theta_0}-\color{green}{\eta}\nabla \ell(\color{blue}{\theta_0}))\approx \ell(\color{blue}{\theta_0})-\color{green}{\eta}\|\nabla \ell(\color{blue}{\theta_0})\|^2\leq \ell(\color{blue}{\theta_0}).\)
  • Interpretation: The loss \(\ell(\color{blue}{\theta_0}-\color{green}{\eta}\nabla \ell(\color{blue}{\theta_0}))\) is likely to be lower than \(\ell(\color{blue}{\theta_0})\), therefore in searching for the lowest positoin of \(\ell\), we should move from \(\color{blue}{\theta_0}\to\color{green}{\theta_0-\eta\nabla \ell(\color{blue}{\theta_0})}\).
  • Gradient Descent Algorithm:
    • Initialiaztion:
      • learning rate: \(\color{green}{\eta}>0\) (small \(\approx 0.001\) or \(0.01\))
      • initial value: \(\color{blue}{\theta_0}\)
      • Maximum iteration: \(N\)
      • Stopping threshold: \(\delta>0\) (small \(< 10^{-5}\)).
  • Update: for t=1,2,...,N: \[\boxed{\color{green}{\theta_{t}:=\theta_{t-1}-\eta\nabla \ell(\theta_{t-1})}.}\]
    • if \(\|\nabla \ell(\theta_{t^*})\|<\delta\) at some step \(t^*\): return \(\color{green}{\theta_{t^*}}\).
    • else: return \(\color{green}{\theta_{N}}\).

Gradient Descent (GD) Algorithm (Cont.)

Stochastic Gradient Descent (SGD)

Stochastic Gradient Descent (SGD) Algorithm

  • Recall that for Logistic Regression, log loss is defined by \[\color{red}{{\cal L}(\beta_0,\vec{\beta})}=-\color{red}{\sum_{i=1}^n}\left[y_i\log(p(1|\text{x}_i))+(1-y_i)\log(p(0|\text{x}_i))\right]:=\color{red}{\sum_{i=1}^n}\ell(y_i,\hat{y}_i).\]
  • In GD, the gradient \(\nabla {\cal L}\) is computed using the whole training data, which may be costly.
  • Using statistics, at each iteration \(t=1,\dots,N\), we can approximate \(\color{red}{\sum_{i=1}^n}\) in the loss by \(\color{green}{\sum_{i\in B_t}}\) using some random subset \(B_t\subset \{1,\dots,n\}\) (called minibatch), i.e., \(\color{red}{{\cal L}(\beta_0,\vec{\beta})}\approx\color{green}{\widehat{\cal L}(\beta_0,\vec{\beta})}=\color{green}{\sum_{i\in B_t}}\ell(y_i,\hat{y}_i)\).
  • Stochastic Gradient Descent Algorithm: (In Logistic Regression: \(\color{blue}{\theta}=(\color{blue}{\beta_0,\vec{\beta}})\))
    • Initialize: \(\eta, N, \theta_0, \delta>0\) (same as in GD), and minibatch size \(b=|B_t|,\forall t=1,2,...,N\).
    • Main loop: for i=1,2,...,N: \[\color{green}{\theta_{t}}:=\color{red}{\theta_{t-1}}-\eta\nabla\color{green}{\widehat{\cal L}}(\color{red}{\theta_{t-1}}).\]
  • Ex: Consider 1st simuated data 👉

Stochastic Gradient Descent (SGD)

Gradient of Log Loss

Optimizing Log Loss in Logistic Regression

  • Log loss for any parameter \(\color{blue}{\beta_0},\color{blue}{\vec{\beta}}\in\mathbb{R}^d\): \[{\cal L}(\color{blue}{\beta_0},\color{blue}{\vec{\beta}})=-\sum_{i=1}^n[y_i\log(p(1|\text{x}_i))+(1-y_i)\log(p(0|\text{x}_i))].\]
  • You should verify that:
    • \(\partial_{\color{blue}{\beta_0}} {\cal L}(\color{blue}{\beta_0},\color{blue}{\vec{\beta}})=\sum_{i=1}^n\partial_{\color{blue}{\beta_0}} \ell(y_i,\hat{y}_i)=-\sum_{i=1}^n(y_i-p(1|\text{x}_i))\in\mathbb{R}\).
    • \(\nabla_{\color{blue}{\vec{\beta}}} {\cal L}(\color{blue}{\beta_0},\color{blue}{\vec{\beta}})=\sum_{i=1}^n\nabla_{\color{blue}{\vec{\beta}}} \ell(y_i,\hat{y}_i)=-\sum_{i=1}^n\underbrace{(y_i-p(1|\text{x}_i))}_{\in\mathbb{R}}\underbrace{\text{x}_i}_{\in\mathbb{R}^d}\).

More about gradient-based optimizations

3 Application

Application on Spam dataset

  • We build Binary Logistic Regression for spam filtering.
  • Standardization often stabilizes the optimization: \[x_j\to\tilde{x}_j=\frac{x_j-\mu_j}{\sigma_j}.\]
Code
from sklearn.linear_model import LogisticRegression
from sklearn.preprocessing import StandardScaler
# Standardization
scaler = StandardScaler()
X_sc_train = scaler.fit_transform(X_train1)
X_sc_test = scaler.transform(X_test1)

# Fit model
logit = LogisticRegression()
logit = logit.fit(X_sc_train, y_train1)
logit_pred = logit.predict(X_sc_test)
logit_pred_pro = logit.predict_proba(X_sc_test)[:,1]
acc = np.mean(logit_pred.flatten() == y_test1.to_numpy().flatten())
sns.set(style="white")
_, ax = plt.subplots(1,1,figsize=(3,1.5))
conf = confusion_matrix(logit_pred, y_test1)
con_fig = ConfusionMatrixDisplay(conf)
con_fig.plot(ax=ax)
ax.set_title(f"Accuracy = {np.round(acc,3)}")
plt.show()

Metric Value
0 ROC AUC 0.971336
1 Recall 0.874359
2 Precision 0.931694
3 F1 Score 0.902116

4 Multinomial Log Reg

4.1 Multinomial Log Reg

  • In this case, \(y\) takes \(M\) distinct values, it’s often encoded to be \(M\)-dimensional vector: \[y=k\Leftrightarrow p=(0,\dots,0,\underbrace{1}_{k\text{th index}},0,\dots,0)^T.\]
  • The model also returns \(M\)-dimensional probability vector where index with highest probability is the predicted class.
  • \(\text{Softmax}:\mathbb{R}^M\to\mathbb{S}_{M-1}=\{p_j\in[0,1]^M:\sum_{j=1}^Mp_j=1\}\) defined by \[\vec{z}\mapsto \vec{s}=\text{Softmax}(z)=\Big(\frac{e^{z_1}}{\sum_{j=1}^Me^{z_j}},\dots,\frac{e^{z_M}}{\sum_{j=1}^Me^{z_j}}\Big).\]
  • It converts any \(M\)-dimensional vector \(\vec{z}\) to \(M\)-dimensional probability vector \(\vec{s}\).

Model

  • \(\text{Softmax}:\mathbb{R}^M\to\mathbb{S}_{M-1}=\{p_j\in[0,1]^M:\sum_{j=1}^Mp_j=1\}\) defined by \[\vec{z}\mapsto \vec{s}=\text{Softmax}(z)=\Big(\frac{e^{z_1}}{\sum_{j=1}^Me^{z_j}},\dots,\frac{e^{z_M}}{\sum_{j=1}^Me^{z_j}}\Big).\]
  • Model: Given parameter matrix \(\color{green}{W}\) of size \(M\times d\) and intercept vector \(\color{green}{\vec{b}}\in\mathbb{R}^d\), the predicted probability of any input data \(\text{x}_i\in\mathbb{R}^d\) is defined by

\[\begin{align*}\color{red}{\hat{p}_i}&=\text{Softmax}(\color{green}{W}\text{x}_i+\color{green}{\vec{b}})\\ &=\text{Softmax}\begin{pmatrix} \color{green}{\begin{bmatrix}w_{11}& \dots & w_{1d}\\ w_{11}& \dots & w_{1d}\\ \vdots & \vdots & \vdots\\ w_{M1}& \dots & w_{Md}\end{bmatrix}}\begin{bmatrix}x_{i1}\\ x_{i2}\\ \vdots\\ x_{id}\end{bmatrix}+\color{green}{\begin{bmatrix}b_{1}\\ b_{2}\\ \vdots\\ b_{M}\end{bmatrix}}\end{pmatrix}=\color{red}{\begin{bmatrix}p_{i1}\\ p_{i2}\\ \vdots\\ p_{iM}\end{bmatrix}}\end{align*}\]

Model

\[\begin{align*}\color{red}{\hat{p}_i}&=\text{Softmax}(\color{green}{W}\text{x}_i+\color{green}{\vec{b}})\\ &=\text{Softmax}\begin{pmatrix} \color{green}{\begin{bmatrix}w_{11}& \dots & w_{1d}\\ w_{11}& \dots & w_{1d}\\ \vdots & \vdots & \vdots\\ w_{M1}& \dots & w_{Md}\end{bmatrix}}\begin{bmatrix}x_{i1}\\ x_{i2}\\ \vdots\\ x_{id}\end{bmatrix}+\color{green}{\begin{bmatrix}b_{1}\\ b_{2}\\ \vdots\\ b_{M}\end{bmatrix}}\end{pmatrix}=\color{red}{\begin{bmatrix}p_{i1}\\ p_{i2}\\ \vdots\\ p_{iM}\end{bmatrix}}\end{align*}\]

Cross-entropy loss

  • We search for the best parameters \(\color{green}{W}\in\mathbb{R}^{M\times d}\) and \(\color{green}{\vec{b}}\in\mathbb{R}^d\) by minimizing Cross Entropy loss: \[\text{CEn}(W,\vec{b})=-\sum_{i=1}^n\sum_{m=1}^M\color{blue}{p_{im}}\log(\color{red}{\hat{p}_{im}}),\] where \(\color{red}{\widehat{\text{p}}_i}=(\color{red}{\hat{p}_{i1}},\color{red}{\dots},\color{red}{\hat{p}_{iM}})\text{ is the predicted probability of }\color{blue}{\text{p}_i}\).

Gradient of Cross-Entropy

Optimizing Cross-entropy in Multinomial Logistic Regression

  • Cross Entropy of any parameter \(\color{green}{W}\in\mathbb{R}^{M\times d}\) and \(\color{green}{\vec{b}}\in\mathbb{R}^d\): \(\text{CEn}(\color{green}{W},\color{green}{\vec{b}})=-\sum_{i=1}^n\sum_{m=1}^M\color{blue}{p_{im}}\log(\color{red}{\widehat{p}_{im}})\).
  • Challenge: Show that
    • \(\nabla_{\color{green}{\vec{b}}} \text{CEn}(\color{green}{W},\color{green}{\vec{b}})=\sum_{i=1}^n\nabla_{\color{green}{\vec{b}}} \ell(\color{blue}{\text{p}_i},\color{red}{\hat{\text{p}}_i})=-\sum_{i=1}^n\underbrace{(\color{blue}{\text{p}_i}-\text{softmax}(\color{green}{W}\text{x}+\color{green}{\vec{b}}))}_{\in\mathbb{R}^d}\).
    • \(\nabla_{\color{green}{W}} \text{CEn}(\color{green}{W},\color{green}{\vec{b}})=\sum_{i=1}^n\nabla_{\color{green}{W}} \ell(\color{blue}{\text{p}_i},\color{red}{\widehat{p}_i})=-\sum_{i=1}^n\underbrace{(\color{blue}{\text{p}_i}-\color{red}{\widehat{\text{p}}_i})}_{\in\mathbb{R}^{d\times 1}}\underbrace{\text{x}_i^T}_{\in\mathbb{R}^{1\times d}}=\underbrace{(\color{red}{\widehat{P}}-\color{blue}{P})^TX}_{\in\mathbb{R}^{d\times d}}\), where

\[\begin{align*} \color{red}{\hat{P}}=\color{red}{\underbrace{\begin{bmatrix} \hat{p}_{11} &\dots & \hat{p}_{1d}\\ \vdots & \vdots & \vdots\\ \hat{p}_{n1} &\dots & \hat{p}_{nd} \end{bmatrix}}_{\text{Matrix of predicted probab}}}, \color{blue}{P}=\color{blue}{\underbrace{\begin{bmatrix} p_{11} &\dots & p_{1d}\\ \vdots & \vdots & \vdots\\ p_{n1} &\dots & p_{nd} \end{bmatrix}}_{\text{One-hot encoded matrix of $y_i$}}}\text{ and } X=\underbrace{\begin{bmatrix} x_{11} &\dots & x_{1d}\\ \vdots & \vdots & \vdots\\ x_{n1} &\dots & x_{nd} \end{bmatrix}}_{\text{Matrix of inputs $x_i$}} \end{align*}\]

Further reading: J. Chiang (2023) and K. Stratos (2018).

Pros

  • Simplicity: It’s easy to understand and implement.
  • Efficiency: It’s not so computationally expensive, making it suitable for large datasets.
  • Interpretability: It converts relative distances from input data to boundary decision into probabilities, which can be meaningfully interpreted.
  • No Scaling Required: It doesn’t require input features to be scaled or standardized (you can also tranform for efficient computation).
  • Works Well with Linearly Separable Data: Performs well when the data is linearly separable.

Cons

  • Assumes Linearity: Assumes a linear relationship between the independent variables and the log-odds of the dependent variable.
  • Sensitivity to Outliers: Outliers can affect the model’s performance and accuracy.
  • Overfitting: Can overfit if the dataset has a large number of features compared to the number of observations.
  • Limited to Binary Outcomes: Standard logistic regression is designed for binary classification and may not perform as well with multiclass classification problems.
  • Assumes Independence of Errors: Assumes that the observations are independent of each other and that there is no multicollinearity among predictors.

🥳 It’s party time 🥂