Zero_To_Hero_Machine_Learning / pages /Logistic_Regression_Algorithm.py
Phaneendrabayi's picture
Update pages/Logistic_Regression_Algorithm.py
003d841 verified
Raw History Blame Contribute Delete
2.73 kB
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).
""")