-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPerceptron.py
More file actions
34 lines (26 loc) · 824 Bytes
/
Perceptron.py
File metadata and controls
34 lines (26 loc) · 824 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
import random as r
class perceptron:
w = [0]*2
def __init__():
for i in range(len(w)):
w[i] = r.random()
#actuation function that process the sum and return either 1 or -1
def actuation_func(n):
if n >= 0:
return 1
elif n < 0:
return -1
def guess(data):
total = 0
for i in range(len(w)):
total += data[i]*weighs[i]
output = actualtion_func(total)
def train(data, point, target):
i = 0
flag = False
while not flag:
while i < len(w):
error = target - data
print(error)
for i in range(len(w)):
w[i] += error * point[i] * lr