-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathperceptron.py
33 lines (26 loc) · 1.37 KB
/
perceptron.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
import numpy as np
import matplotlib.pyplot as plt
X1 = np.array([-0.62231486, -0.96251306, 0.42269922, -1.452746 , -0.66915783,
-0.35716016, 0.49505163, -1.8117848 , 0.53376487, -1.86923838,
0.71434306, -0.4055084 , 0.82887254, 0.81221287, 1.44280951,
-0.45599278, -1.16715888, 1.08913131, -1.61470741, 1.61113001,
-1.4532688 , 1.04872588, -1.52312195, -1.62831727, -0.25191539])
X2 = np.array([-1.67427011, -1.81046748, 1.20384694, -0.41572751, 0.66851908,
-1.75435288, -1.57532207, -1.22329618, -0.84375819, 0.52873296,
-1.10837773, 0.04612922, 0.67696196, 0.84618152, -0.77362548,
0.99153072, 1.7896494 , -0.38343121, -0.21337742, 0.64754817,
0.36719101, 0.23132427, 1.07029963, 1.62919909, -1.53920827])
Y = np.array([ 1., -1., -1., -1., -1.,
1., 1., -1., 1., -1.,
1., -1., 1., 1., 1.,
-1., -1., 1., -1., 1.,
-1., 1., -1., -1., 1.])
def plot_data(filename = 'data0'):
fig = plt.figure()
ax = fig.add_subplot(111)
plt.scatter(X1[Y >= 0], X2[Y >= 0], s = 80, c = 'b', marker = "o")
plt.scatter(X1[Y < 0], X2[Y < 0], s = 80, c = 'r', marker = "^")
ax.set_xlim(-2, 2)
ax.set_ylim(-2, 2)
fig.set_size_inches(6, 6)
plt.show()