from sklearn import svm

# Tập dữ liệu
xor_data = [
    # P, Q, Result
    [0, 0, 0],
    [0, 1, 1],
    [1, 0, 1],
    [1, 1, 0]
]

# Phân loại data & label
data = []
label = []
for row in xor_data:
    p = row[0]
    q = row[1]
    r = row[2]
    data.append([p, q])
    label.append(r)

# Training 
clf = svm.SVC()
clf.fit(data, label)

# Dự đoán
predict = clf.predict(data)
print("result :", predict)

# Report
ok = 0; total = 0
for idx, answer in enumerate(label):
    p = predict[idx]
    if p == answer: ok += 1
    total += 1
print("Correct Rate :", ok, "/", total, "=", ok/total)

f5d299a654ae240fee0457c3b3072531f3a75e4d
<mask token>

<mask token>
for row in xor_data:
    p = row[0]
    q = row[1]
    r = row[2]
    data.append([p, q])
    label.append(r)
<mask token>
clf.fit(data, label)
<mask token>
print('result :', predict)
<mask token>
for idx, answer in enumerate(label):
    p = predict[idx]
    if p == answer:
        ok += 1
    total += 1
print('Correct Rate :', ok, '/', total, '=', ok / total)

<mask token>
xor_data = [[0, 0, 0], [0, 1, 1], [1, 0, 1], [1, 1, 0]]
data = []
label = []
for row in xor_data:
    p = row[0]
    q = row[1]
    r = row[2]
    data.append([p, q])
    label.append(r)
clf = svm.SVC()
clf.fit(data, label)
predict = clf.predict(data)
print('result :', predict)
ok = 0
total = 0
for idx, answer in enumerate(label):
    p = predict[idx]
    if p == answer:
        ok += 1
    total += 1
print('Correct Rate :', ok, '/', total, '=', ok / total)

from sklearn import svm
xor_data = [[0, 0, 0], [0, 1, 1], [1, 0, 1], [1, 1, 0]]
data = []
label = []
for row in xor_data:
    p = row[0]
    q = row[1]
    r = row[2]
    data.append([p, q])
    label.append(r)
clf = svm.SVC()
clf.fit(data, label)
predict = clf.predict(data)
print('result :', predict)
ok = 0
total = 0
for idx, answer in enumerate(label):
    p = predict[idx]
    if p == answer:
        ok += 1
    total += 1
print('Correct Rate :', ok, '/', total, '=', ok / total)

from sklearn import svm

# Tập dữ liệu
xor_data = [
    # P, Q, Result
    [0, 0, 0],
    [0, 1, 1],
    [1, 0, 1],
    [1, 1, 0]
]

# Phân loại data & label
data = []
label = []
for row in xor_data:
    p = row[0]
    q = row[1]
    r = row[2]
    data.append([p, q])
    label.append(r)

# Training 
clf = svm.SVC()
clf.fit(data, label)

# Dự đoán
predict = clf.predict(data)
print("result :", predict)

# Report
ok = 0; total = 0
for idx, answer in enumerate(label):
    p = predict[idx]
    if p == answer: ok += 1
    total += 1
print("Correct Rate :", ok, "/", total, "=", ok/total)
