-
Notifications
You must be signed in to change notification settings - Fork 0
/
prml_linear.py
29 lines (21 loc) · 861 Bytes
/
prml_linear.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
from prml_perceptron import Perceptron
f = lambda x : x
class LinearUnit(Perceptron):
def __init__(self,input_num):
Perceptron.__init__(self,input_num,f)
def get_training_dataset():
input_vecs = [[5],[3],[8],[1.4],[10.1]]
labels = [5500,2300,7600,1800,11400]
return input_vecs,labels
def train_linear_unit():
lu = LinearUnit(1)
input_vecs,labels = get_training_dataset()
lu.train(input_vecs,labels,10,0.01)
return lu
if __name__ == '__main__':
linear_unit = train_linear_unit()
print linear_unit
print 'Work 3.4 years,mouthly salary = %.2f' % linear_unit.predict([3.4])
print 'Work 15 years,mouthly salary = %.2f' % linear_unit.predict([15])
print 'Work 1.5 years,mouthly salary = %.2f' % linear_unit.predict([1.5])
print 'Work 6.3 years,mouthly salary = %.2f' % linear_unit.predict([6.3])