-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.py
More file actions
36 lines (25 loc) · 790 Bytes
/
Main.py
File metadata and controls
36 lines (25 loc) · 790 Bytes
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
import numpy as np
import arff
data = arff.load(open('chronic_kidney_disease_full.arff', 'rb'))
print(data)
data, meta = arff.loadarff('chronic_kidney_disease_full.arff')
print(data)
print(meta)
class LogReg:
def __init__(self, loops, a=0.01):
self.lr = a
self.loops = loops
def cost(self, h, y):
return (-y * np.log(h) - (1 - y) * np.log(1 - h)).mean()
def sigmoid(z):
y = 1 / (1 + np.exp(-z))
return y
def fit(self, X, y):
# weights vector
self.theta = np.zeros(X.shape[1])
# weights training
for i in range(self.loops):
z = np.dot(X, self.theta)
h = self.sigmoid(z)
gradient = np.dot(X.T, (h - y)) / y.size
self.theta -= self.lr * gradient