-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogisticRegression.py
More file actions
55 lines (36 loc) · 823 Bytes
/
logisticRegression.py
File metadata and controls
55 lines (36 loc) · 823 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# -*- coding: utf-8 -*-
"""
Created on Thu Oct 15 08:26:19 2020
@author: MBILAL 07
"""
import numpy as np
import math
def sigmoid(x):
return 1 / (1 + math.exp(-x))
def loss_Function(y,yP):
if(yP==0):
yP+=0.00001
return (y*math.log(yP))-((1-y)*math.log(1-yP))
count=0
while(True):
X=np.random.rand(3,100)
Y=np.random.rand(100,1)
b=np.random.rand();
lR=0.5
weights=np.random.rand(3,1)
z=weights.T.dot(X)+b;
sigmoid_v=np.vectorize(sigmoid)
loss_v=np.vectorize(loss_Function)
A=sigmoid_v(z);
dz=A.T-Y
db=np.sum(dz)/300
dw=X.dot(dz)/300
weights-=lR*dw
b-=lR*db
loss=np.sum( loss_v(Y.T,A))/300
count+=1
if(loss<0.001):
break;
print(loss,count);
# aMean=np.sum(loss)/100
# print(loss)