pranayreddy316 commited on
Commit
eac17f1
·
verified ·
1 Parent(s): ba969a6

Upload The Logistic_Regression_Algorithm.py

Browse files
pages/The Logistic_Regression_Algorithm.py ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+
4
+ st.set_page_config(page_title="Logistic Regression Explorer")
5
+
6
+ st.title("📊 Logistic Regression - Classifier")
7
+
8
+ st.header("🔍 Logistic Regression - In Depth")
9
+
10
+ st.markdown("""
11
+ ## 📘 What is Logistic Regression?
12
+ 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).
13
+
14
+ It predicts the **probability** of a class label using the **logistic (sigmoid)** function.
15
+
16
+ ---
17
+
18
+ ## 📈 Mathematical Formulation
19
+ The model predicts:
20
+
21
+ \[ P(y=1|x) = \frac{1}{1 + e^{-z}} \quad \text{where} \quad z = w^Tx + b \]
22
+
23
+ - `x`: input features
24
+ - `w`: weights
25
+ - `b`: bias
26
+ - `sigmoid(z)`: squashes values between 0 and 1
27
+
28
+ ---
29
+
30
+ ## 🔑 Key Concepts
31
+ - **Linear Decision Boundary**: Separates classes using a straight line/hyperplane.
32
+ - **Sigmoid Activation**: Converts linear output into probability.
33
+ - **Cross Entropy Loss**: Cost function to optimize.
34
+ - **Maximum Likelihood Estimation (MLE)**: Estimates the best-fit parameters.
35
+
36
+ ---
37
+
38
+ ## 🔧 Hyperparameters Explained
39
+
40
+ | Parameter | Description |
41
+ |-----------|-------------|
42
+ | `penalty` | Regularization method (`l1`, `l2`, `elasticnet`, `none`). |
43
+ | `C` | Inverse of regularization strength. Smaller values mean stronger regularization. |
44
+ | `solver` | Algorithm to optimize weights (e.g., `liblinear`, `saga`, `lbfgs`). |
45
+ | `max_iter` | Maximum number of iterations for convergence. |
46
+ | `fit_intercept` | Whether to include the bias term. |
47
+ | `class_weight` | Assigns weights to classes (e.g., `balanced` handles imbalanced data). |
48
+ | `multi_class` | Type of classification problem (`ovr`, `multinomial`). |
49
+
50
+ ---
51
+
52
+ ## ✅ Advantages
53
+ - Simple and efficient for binary classification.
54
+ - Outputs probability values.
55
+ - Works well when the relationship is approximately linear.
56
+
57
+ ## ❌ Disadvantages
58
+ - Not suitable for non-linear problems (unless using feature engineering).
59
+ - Assumes no multicollinearity and linear separability.
60
+
61
+ ---
62
+
63
+ ## 🧪 Optuna for Hyperparameter Tuning (Explanation Only)
64
+ - `Optuna` is a powerful library for **automated hyperparameter optimization**.
65
+ - For Logistic Regression, Optuna can help optimize:
66
+ - `C` (regularization strength)
67
+ - `solver`
68
+ - `penalty`
69
+ - Objective: **maximize validation accuracy** or **F1-score**.
70
+
71
+ It performs trials to find the best parameter combination, using techniques like TPE (Tree Parzen Estimator).
72
+
73
+ ---
74
+
75
+ ## 📌 Use Cases
76
+ - Spam detection
77
+ - Medical diagnosis (disease prediction)
78
+ - Customer churn prediction
79
+ - Credit risk assessment
80
+
81
+ ---
82
+
83
+ 📎 **Tip**: Scale your data before applying Logistic Regression (especially with `l1` or `l2` regularization).
84
+ """)