def main(): g = gd() patientv = [pinfo[1:] for pname, pinfo in g.REMISSED_PATIENTS.items()] print len(patientv[0]) m = model(len(patientv[0])-2) train_in = [x[:265] for x in patientv[:120]] train_out = [x[266] for x in patientv[:120]] train_set= zip(train_out,train_in) m.train(train_set,0.01) test = [x[:266] for x in patientv[120:]] for x in test: x = np.insert(x,0,1) print m.reg(x)
def main(): from read import getData as gd g = gd() tset = g.get_trainset(0.8, 265, vectorize=True) train_data = tset[0] test_data = tset[1] n = Network([265, 100, 100, 2]) # train n.train(train_data, 2000, 20, 0.0001) for i in xrange(len(test_data)): print n.feed(test_data[i][1]) print test_data[i][0]
def cost_derivative(self,x,y): return (y - self.reg(x)) def cost_func(self,train_set): suma = [] for y,x in train_set: x = np.insert(x,0,1) a = 1.0/2.0 *(y-self.reg(x))**2 suma.append(a) sum = np.sum(suma) return 1.0/len(train_set) * sum def reg(self,x): output = np.dot(self.parameters.transpose(),x) #print output return output from read import getData as gd if __name__ =='__main__': g = gd(scale=True) train_data = g.get_trainset(0.8,266) train_set = train_data[0] test_set = train_data[1] n = RegModel(266) y = test_set[0][1] y = np.insert(y,0,1) n.train(train_set,0.000001,1000) x = test_set[0][0] print n.reg(y) print x with open("parameters.txt",'w') as f: f.write(np.array_str(n.parameters))