-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path(WIP)LogisticRegression.py
77 lines (56 loc) · 1.41 KB
/
(WIP)LogisticRegression.py
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
"""
WIP
$ Author: Risha $
$ https://github.com/Risha37 $
$ Revision: 1.0 $
TODO
-
"""
import numpy as np
class LogisticRegression():
def __init__(self):
"""
Description
----------
"""
pass
def sigmoid(self,
x
):
"""
Description
----------
Parameters
----------
-
Returns
----------
-
"""
return 1/(1+np.exp(-x))
def fit(self,
X,
y,
learning_rate: float=0.1,
epochs: int=20,
random_state: int=42
):
"""
Description
----------
Parameters
----------
-
Returns
----------
-
"""
np.random.seed(random_state)
#Initialise random weights
W = np.random.randn(X.shape[1]+1, 1) if initial_weight is None else initial_weight
#Add ones column vector to represent x_0
X = np.append(X, np.ones((len(X), 1)), axis=1)
for epoch in range(epochs):
z = X @ W
h_x = self.sigmoid(z)
J = (-1/m) * np.sum((y @ np.log(h_x)) + ((1-y) @ np.log(1-h_x)))