Download pages/Logistic_Regression_Algorithm.py from Phaneendrabayi/Zero_To_Hero_Machine_Learning: direct link, hf CLI and curl.
- Browser
- Download file 2.73 kB
-
https://huggingface.co/spaces/Phaneendrabayi/Zero_To_Hero_Machine_Learning/resolve/main/pages/Logistic_Regression_Algorithm.py
- Command line
-
hf download hf://spaces/Phaneendrabayi/Zero_To_Hero_Machine_Learning/pages/Logistic_Regression_Algorithm.py
-
curl -L -o Logistic_Regression_Algorithm.py https://huggingface.co/spaces/Phaneendrabayi/Zero_To_Hero_Machine_Learning/resolve/main/pages/Logistic_Regression_Algorithm.py
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). | |
| """) | |