x1 = (3,3) y1=1
x2 = (4,3) y2 = 1
x3 = (1,1) y3 =-1
import pandas as pd
import numpy as np
a = [1, 2, 3, 4]
x = [(3, 3, 1), (4, 3, 1), (1, 1, -1)]
data = pd.DataFrame(x, index=[1, 2, 3], columns=["x0", "x1", "类别"])
print(data)
w = np.transpose([0, 0])
b = 0
y = data.iloc[:, 2]
x0 = data.iloc[:, 1]
x1 = data.iloc[:, 0]
a = pd.Series([0, 0, 0], index=[1, 2, 3])
while 1:
for i in range(1, len(data)+1):
a[i] = y[i] * (np.dot(w, [x0[i], x1[i]]) + b)
if a[i] <= 0:
w = w + np.transpose(np.dot(y[i], [x0[i], x1[i]]))
b = b + y[i]
break
if a[1] > 0 and a[2] > 0 and a[3] > 0:
break
print(w, b)