-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLayer Neural Network (2).py
More file actions
58 lines (45 loc) · 1.15 KB
/
Layer Neural Network (2).py
File metadata and controls
58 lines (45 loc) · 1.15 KB
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
# -*- coding: utf-8 -*-
"""
Created on Tue Apr 5 16:35:14 2016
@author: yiz613
"""
import numpy as np
import unPickle
import numpy
import pickleGenerator
# sigmoid function
def nonlin(x,deriv=False):
if(deriv==True):
return x*(1-x)
return 1/(1+np.exp(-x))
test_set, lengthOfInput_test_set = unPickle.convertData('encoded_test_pickle')
a, b = test_set
# input dataset
X = a
# output dataset
y = np.array([b.tolist()]).T
# seed random numbers to make calculation
#np.random.seed(1)
# initialize weights randomly with mean 0
syn0 = 2*np.random.random((200,1)) - 1
for iter in range(1000):
# forward propagation
l0 = X
l1 = nonlin(np.dot(l0,syn0))
# how much did we miss?
l1_error = y - l1
# multiply how much we missed by the
# slope of the sigmoid at the values in l1
l1_delta = l1_error * nonlin(l1,True)
# update weights
syn0 += np.dot(l0.T,l1_delta)
print ("Output After Training:")
hmm = l1.tolist()
for xxx in hmm:
if (xxx[0]>0.88):
print (xxx)
import csv
with open('test.csv', 'w', newline='') as fp:
a = csv.writer(fp, delimiter=',')
data = hmm
a.writerows(data)