-
Notifications
You must be signed in to change notification settings - Fork 0
/
fisher_scoring.py
92 lines (58 loc) · 1.27 KB
/
fisher_scoring.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
from __future__ import division
import numpy as np
import os
import matplotlib as mpl
mpl.use('Agg')
import matplotlib.pyplot as plt
os.chdir('D:/Krishna/Acads/Q4/ML/HW')
def load_data():
X = np.genfromtxt('logistic_x.txt')
Y = np.genfromtxt('logistic_y.txt')
return X, Y
def add_intercept(X_):
m, n = X_.shape
X = np.zeros((m, n + 1))
################
################
return X
def calc_grad(X, Y, theta):
m, n = X.shape
grad = np.zeros(theta.shape)
##############
##############
return grad
##
## This function is useful to debug
## Ensure that loss is going down over iterations
##
def calc_loss(X, Y, theta):
m, n = X.shape
loss = 0.
###########
###########
return loss
def calc_hessian(X, Y, theta):
m, n = X.shape
H = np.zeros((n, n))
##############
#############
return H
def logistic_regression(X, Y):
m, n = X.shape
theta = np.zeros(n)
############
############
return theta
def plot(X, Y, theta):
plt.figure()
############
############
plt.savefig('ps1q1c.png')
return
def main():
X_, Y = load_data()
X = add_intercept(X_)
theta = logistic_regression(X, Y)
plot(X, Y, theta)
if __name__ == '__main__':
main()