-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy path0002-.patch
More file actions
228 lines (225 loc) · 5.43 KB
/
0002-.patch
File metadata and controls
228 lines (225 loc) · 5.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
From 01c579bb532ad5d52d4d5d77d87f9ef6bd299e9f Mon Sep 17 00:00:00 2001
From: "Adnan Amin, Ph.D." <geoamins@gmail.com>
Date: Sun, 8 Mar 2026 13:36:32 +0500
Subject: [PATCH 2/2] ...
---
.../2featurs_logistic_regression_GD.ipynb | 25 ++-
.../step_by_step_logistic regression.ipynb | 144 ++++++++++++++++++
2 files changed, 163 insertions(+), 6 deletions(-)
diff --git a/ML Week 5.1/2featurs_logistic_regression_GD.ipynb b/ML Week 5.1/2featurs_logistic_regression_GD.ipynb
index d64b1e2..218a168 100644
--- a/ML Week 5.1/2featurs_logistic_regression_GD.ipynb
+++ b/ML Week 5.1/2featurs_logistic_regression_GD.ipynb
@@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 1,
"id": "9675b8d1",
"metadata": {},
"outputs": [],
@@ -28,7 +28,7 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 2,
"id": "d9df748a",
"metadata": {},
"outputs": [],
@@ -43,7 +43,7 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 3,
"id": "b12c8bdd",
"metadata": {},
"outputs": [],
@@ -56,7 +56,7 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 4,
"id": "496b0174",
"metadata": {},
"outputs": [],
@@ -80,10 +80,23 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 5,
"id": "3a45614b",
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Final Weights:\n",
+ " [[0.66763282]\n",
+ " [0.66763282]]\n",
+ "Final Bias:\n",
+ " -4.395402776214578\n",
+ "Final Loss: 0.21133419669571119\n"
+ ]
+ }
+ ],
"source": [
"print(\"Final Weights:\\n\", w)\n",
"print(\"Final Bias:\\n\", b)\n",
diff --git a/ML Week 5.1/step_by_step_logistic regression.ipynb b/ML Week 5.1/step_by_step_logistic regression.ipynb
index e69de29..63a5497 100644
--- a/ML Week 5.1/step_by_step_logistic regression.ipynb
+++ b/ML Week 5.1/step_by_step_logistic regression.ipynb
@@ -0,0 +1,144 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "id": "509e31f9",
+ "metadata": {},
+ "source": [
+ "### Logistic Regression From Scratch (1 Feature)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 2,
+ "id": "c82bf0e3",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "import numpy as np\n",
+ "\n",
+ "# Dataset\n",
+ "X = np.array([1, 2, 3]).reshape(-1, 1) # feature\n",
+ "y = np.array([0, 0, 1]).reshape(-1, 1) # labels\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 3,
+ "id": "4af339cb",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Initialize parameters\n",
+ "w = np.zeros((1, 1)) # w=[0]\n",
+ "b = 0\n",
+ "alpha = 0.1\n",
+ "n = len(y)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 4,
+ "id": "65b667f6",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Sigmoid function\n",
+ "\n",
+ "def sigmoid(z):\n",
+ " return 1 / (1 + np.exp(-z))"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 5,
+ "id": "a8a85443",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Iteration 1\n",
+ "w = 0.000000, b = -0.016667\n",
+ "Loss = 0.693147\n",
+ "-------------------------\n",
+ "Iteration 2\n",
+ "w = 0.000833, b = -0.032917\n",
+ "Loss = 0.690404\n",
+ "-------------------------\n",
+ "Iteration 3\n",
+ "w = 0.002382, b = -0.048802\n",
+ "Loss = 0.687783\n",
+ "-------------------------\n",
+ "Iteration 4\n",
+ "w = 0.004544, b = -0.064368\n",
+ "Loss = 0.685256\n",
+ "-------------------------\n",
+ "Iteration 5\n",
+ "w = 0.007231, b = -0.079653\n",
+ "Loss = 0.682803\n",
+ "-------------------------\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Training loop\n",
+ "\n",
+ "for i in range(5):\n",
+ " \n",
+ " # Forward pass\n",
+ " z = np.dot(X, w) + b\n",
+ " y_hat = sigmoid(z)\n",
+ " \n",
+ " # Compute loss (Binary Cross Entropy)\n",
+ " loss = -(1/n) * np.sum(\n",
+ " y * np.log(y_hat) + (1 - y) * np.log(1 - y_hat)\n",
+ " )\n",
+ " \n",
+ " # Compute gradients\n",
+ " dw = (1/n) * np.dot(X.T, (y_hat - y))\n",
+ " db = (1/n) * np.sum(y_hat - y)\n",
+ " \n",
+ " # Update parameters\n",
+ " w = w - alpha * dw\n",
+ " b = b - alpha * db\n",
+ " \n",
+ " # Print results\n",
+ " print(f\"Iteration {i+1}\")\n",
+ " print(f\"w = {w.flatten()[0]:.6f}, b = {b:.6f}\")\n",
+ " print(f\"Loss = {loss:.6f}\")\n",
+ " print(\"-------------------------\")"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "ef0566a8",
+ "metadata": {},
+ "outputs": [],
+ "source": []
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 3",
+ "language": "python",
+ "name": "python3"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 3
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython3",
+ "version": "3.13.7"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 5
+}
--
2.51.0.windows.1