File size: 2,728 Bytes
48ab9b9
 
 
003d841
48ab9b9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import streamlit as st
import pandas as pd

st.set_page_config(page_title="Logistic Regression Explorer")

st.title("πŸ“Š Logistic Regression - Classifier")

st.header("πŸ” Logistic Regression - In Depth")

st.markdown("""
## πŸ“˜ What is Logistic Regression?
Logistic Regression is a **supervised learning** algorithm used for **binary or multi-class classification** tasks. Despite the name, it's a classification algorithm (not regression).

It predicts the **probability** of a class label using the **logistic (sigmoid)** function.

---

## πŸ“ˆ Mathematical Formulation
The model predicts:

\[ P(y=1|x) = \frac{1}{1 + e^{-z}} \quad \text{where} \quad z = w^Tx + b \]

- `x`: input features
- `w`: weights
- `b`: bias
- `sigmoid(z)`: squashes values between 0 and 1

---

## πŸ”‘ Key Concepts
- **Linear Decision Boundary**: Separates classes using a straight line/hyperplane.
- **Sigmoid Activation**: Converts linear output into probability.
- **Cross Entropy Loss**: Cost function to optimize.
- **Maximum Likelihood Estimation (MLE)**: Estimates the best-fit parameters.

---

## πŸ”§ Hyperparameters Explained

| Parameter | Description |
|-----------|-------------|
| `penalty` | Regularization method (`l1`, `l2`, `elasticnet`, `none`). |
| `C` | Inverse of regularization strength. Smaller values mean stronger regularization. |
| `solver` | Algorithm to optimize weights (e.g., `liblinear`, `saga`, `lbfgs`). |
| `max_iter` | Maximum number of iterations for convergence. |
| `fit_intercept` | Whether to include the bias term. |
| `class_weight` | Assigns weights to classes (e.g., `balanced` handles imbalanced data). |
| `multi_class` | Type of classification problem (`ovr`, `multinomial`). |

---

## βœ… Advantages
- Simple and efficient for binary classification.
- Outputs probability values.
- Works well when the relationship is approximately linear.

## ❌ Disadvantages
- Not suitable for non-linear problems (unless using feature engineering).
- Assumes no multicollinearity and linear separability.

---

## πŸ§ͺ Optuna for Hyperparameter Tuning (Explanation Only)
- `Optuna` is a powerful library for **automated hyperparameter optimization**.
- For Logistic Regression, Optuna can help optimize:
    - `C` (regularization strength)
    - `solver`
    - `penalty`
- Objective: **maximize validation accuracy** or **F1-score**.

It performs trials to find the best parameter combination, using techniques like TPE (Tree Parzen Estimator).

---

## πŸ“Œ Use Cases
- Spam detection
- Medical diagnosis (disease prediction)
- Customer churn prediction
- Credit risk assessment

---

πŸ“Ž **Tip**: Scale your data before applying Logistic Regression (especially with `l1` or `l2` regularization).
""")