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). """)