Spaces:
Sleeping
Sleeping
Update pages/12_Logistic_Regression.py
Browse files- pages/12_Logistic_Regression.py +43 -16
pages/12_Logistic_Regression.py
CHANGED
|
@@ -30,7 +30,25 @@ st.sidebar.markdown("---")
|
|
| 30 |
|
| 31 |
st.markdown("<h1 style='text-align: center;'>๐ Logistic Regression (Theory)</h1>", unsafe_allow_html=True)
|
| 32 |
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
st.write("""
|
| 35 |
Logistic Regression is a **supervised learning algorithm** used for **classification tasks**.
|
| 36 |
- Mostly used for **binary classification**
|
|
@@ -40,7 +58,8 @@ with st.expander("๐ What is Logistic Regression?"):
|
|
| 40 |
โ ๏ธ Assumption: The data should be **linearly separable** or nearly so.
|
| 41 |
""")
|
| 42 |
|
| 43 |
-
|
|
|
|
| 44 |
st.write("""
|
| 45 |
Initially, people used **step function** for classification:
|
| 46 |
|
|
@@ -61,7 +80,8 @@ with st.expander("โ๏ธ Step vs Sigmoid Function"):
|
|
| 61 |
- \\( z = 0 \\) โ output = 0.5
|
| 62 |
""")
|
| 63 |
|
| 64 |
-
|
|
|
|
| 65 |
st.write("""
|
| 66 |
Logistic Regression uses **Log Loss** (or Binary Cross Entropy) for optimization:
|
| 67 |
$$
|
|
@@ -72,7 +92,8 @@ with st.expander("๐งฎ Loss Function in Logistic Regression"):
|
|
| 72 |
- Minimize this loss using **Gradient Descent**
|
| 73 |
""")
|
| 74 |
|
| 75 |
-
|
|
|
|
| 76 |
st.write("""
|
| 77 |
Gradient Descent updates weights to minimize loss:
|
| 78 |
$$
|
|
@@ -90,8 +111,10 @@ with st.expander("๐ Gradient Descent & Learning Rate"):
|
|
| 90 |
- **Stochastic (SGD)**: Updates per data point
|
| 91 |
- **Mini-Batch**: Updates per small batch โ widely used
|
| 92 |
""")
|
| 93 |
-
|
| 94 |
-
|
|
|
|
|
|
|
| 95 |
st.subheader("1๏ธโฃ Softmax Regression")
|
| 96 |
st.write("""
|
| 97 |
Generalizes binary logistic regression to multi-class using **Softmax Function**:
|
|
@@ -118,7 +141,8 @@ with st.expander("๐ข Multiclass Logistic Regression"):
|
|
| 118 |
Then pick the class with the highest confidence score.
|
| 119 |
""")
|
| 120 |
|
| 121 |
-
|
|
|
|
| 122 |
st.write("""
|
| 123 |
Regularization helps reduce **overfitting** by penalizing large weights.
|
| 124 |
- **L1 (Lasso)**: \\( \\lambda \\sum |w| \\) โ Feature selection
|
|
@@ -128,7 +152,8 @@ with st.expander("๐งฒ Regularization in Logistic Regression"):
|
|
| 128 |
โ๏ธ Helps balance **bias vs variance**
|
| 129 |
""")
|
| 130 |
|
| 131 |
-
|
|
|
|
| 132 |
st.write("""
|
| 133 |
Multicollinearity = when predictors are highly correlated.
|
| 134 |
๐ฏ Check using **VIF (Variance Inflation Factor)**:
|
|
@@ -139,7 +164,8 @@ with st.expander("๐ Detecting Multicollinearity"):
|
|
| 139 |
- Applying regularization
|
| 140 |
""")
|
| 141 |
|
| 142 |
-
|
|
|
|
| 143 |
st.table([
|
| 144 |
["penalty", "Regularization type ('l1', 'l2', 'elasticnet', None)"],
|
| 145 |
["dual", "Use dual formulation (for liblinear only)"],
|
|
@@ -154,12 +180,13 @@ with st.expander("โ๏ธ Hyperparameters in Logistic Regression"):
|
|
| 154 |
["l1_ratio", "Used with ElasticNet"],
|
| 155 |
])
|
| 156 |
|
| 157 |
-
|
| 158 |
-
st.
|
| 159 |
-
st.markdown("""
|
| 160 |
-
<a href='https://colab.research.google.com/drive/1IiZmfkCcMltcE5-r5PbQqRpj_maR_M-f?usp=sharing' target='_blank'>
|
| 161 |
-
๐ Open Logistic Regression Notebook
|
| 162 |
-
</a>
|
| 163 |
-
""", unsafe_allow_html=True)
|
| 164 |
|
|
|
|
| 165 |
st.success("Logistic Regression is simple yet powerful. Master it before diving into complex models!")
|
|
|
|
| 30 |
|
| 31 |
st.markdown("<h1 style='text-align: center;'>๐ Logistic Regression (Theory)</h1>", unsafe_allow_html=True)
|
| 32 |
|
| 33 |
+
section = st.radio(
|
| 34 |
+
"๐ Choose a Topic",
|
| 35 |
+
[
|
| 36 |
+
"Introduction",
|
| 37 |
+
"Step vs Sigmoid",
|
| 38 |
+
"Loss Function",
|
| 39 |
+
"Gradient Descent",
|
| 40 |
+
"Multiclass Logistic Regression",
|
| 41 |
+
"Regularization",
|
| 42 |
+
"Multicollinearity",
|
| 43 |
+
"Hyperparameters",
|
| 44 |
+
"Colab Notebook"
|
| 45 |
+
],
|
| 46 |
+
horizontal=True
|
| 47 |
+
)
|
| 48 |
+
|
| 49 |
+
# Section Content
|
| 50 |
+
if section == "Introduction":
|
| 51 |
+
st.header("๐ What is Logistic Regression?")
|
| 52 |
st.write("""
|
| 53 |
Logistic Regression is a **supervised learning algorithm** used for **classification tasks**.
|
| 54 |
- Mostly used for **binary classification**
|
|
|
|
| 58 |
โ ๏ธ Assumption: The data should be **linearly separable** or nearly so.
|
| 59 |
""")
|
| 60 |
|
| 61 |
+
elif section == "Step vs Sigmoid":
|
| 62 |
+
st.header("โ๏ธ Step vs Sigmoid Function")
|
| 63 |
st.write("""
|
| 64 |
Initially, people used **step function** for classification:
|
| 65 |
|
|
|
|
| 80 |
- \\( z = 0 \\) โ output = 0.5
|
| 81 |
""")
|
| 82 |
|
| 83 |
+
elif section == "Loss Function":
|
| 84 |
+
st.header("๐งฎ Loss Function in Logistic Regression")
|
| 85 |
st.write("""
|
| 86 |
Logistic Regression uses **Log Loss** (or Binary Cross Entropy) for optimization:
|
| 87 |
$$
|
|
|
|
| 92 |
- Minimize this loss using **Gradient Descent**
|
| 93 |
""")
|
| 94 |
|
| 95 |
+
elif section == "Gradient Descent":
|
| 96 |
+
st.header("๐ Gradient Descent & Learning Rate")
|
| 97 |
st.write("""
|
| 98 |
Gradient Descent updates weights to minimize loss:
|
| 99 |
$$
|
|
|
|
| 111 |
- **Stochastic (SGD)**: Updates per data point
|
| 112 |
- **Mini-Batch**: Updates per small batch โ widely used
|
| 113 |
""")
|
| 114 |
+
|
| 115 |
+
elif section == "Multiclass Logistic Regression":
|
| 116 |
+
st.header("๐ข Multiclass Logistic Regression")
|
| 117 |
+
|
| 118 |
st.subheader("1๏ธโฃ Softmax Regression")
|
| 119 |
st.write("""
|
| 120 |
Generalizes binary logistic regression to multi-class using **Softmax Function**:
|
|
|
|
| 141 |
Then pick the class with the highest confidence score.
|
| 142 |
""")
|
| 143 |
|
| 144 |
+
elif section == "Regularization":
|
| 145 |
+
st.header("๐งฒ Regularization in Logistic Regression")
|
| 146 |
st.write("""
|
| 147 |
Regularization helps reduce **overfitting** by penalizing large weights.
|
| 148 |
- **L1 (Lasso)**: \\( \\lambda \\sum |w| \\) โ Feature selection
|
|
|
|
| 152 |
โ๏ธ Helps balance **bias vs variance**
|
| 153 |
""")
|
| 154 |
|
| 155 |
+
elif section == "Multicollinearity":
|
| 156 |
+
st.header("๐ Detecting Multicollinearity")
|
| 157 |
st.write("""
|
| 158 |
Multicollinearity = when predictors are highly correlated.
|
| 159 |
๐ฏ Check using **VIF (Variance Inflation Factor)**:
|
|
|
|
| 164 |
- Applying regularization
|
| 165 |
""")
|
| 166 |
|
| 167 |
+
elif section == "Hyperparameters":
|
| 168 |
+
st.header("โ๏ธ Hyperparameters in Logistic Regression")
|
| 169 |
st.table([
|
| 170 |
["penalty", "Regularization type ('l1', 'l2', 'elasticnet', None)"],
|
| 171 |
["dual", "Use dual formulation (for liblinear only)"],
|
|
|
|
| 180 |
["l1_ratio", "Used with ElasticNet"],
|
| 181 |
])
|
| 182 |
|
| 183 |
+
elif section == "Colab Notebook":
|
| 184 |
+
st.header("๐ Google Colab Notebook")
|
| 185 |
+
st.markdown("""
|
| 186 |
+
<a href='https://colab.research.google.com/drive/1IiZmfkCcMltcE5-r5PbQqRpj_maR_M-f?usp=sharing' target='_blank'>
|
| 187 |
+
๐ Open Logistic Regression Notebook
|
| 188 |
+
</a>
|
| 189 |
+
""", unsafe_allow_html=True)
|
| 190 |
|
| 191 |
+
st.markdown("---")
|
| 192 |
st.success("Logistic Regression is simple yet powerful. Master it before diving into complex models!")
|