Created
September 23, 2018 06:12
-
-
Save Inazuma110/7883d82d42f65a2d3eebf113765621a4 to your computer and use it in GitHub Desktop.
XOR 演算
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sklearn import svm | |
xor_date = [ | |
[0, 0, 0], | |
[0, 1, 1], | |
[1, 0, 1], | |
[1, 1, 0]] | |
data = [] | |
label = [] | |
for row in xor_date: | |
p = row[0] | |
q = row[1] | |
r = row[2] | |
data.append([p, q]) | |
label.append(r) | |
clf = svm.SVC() | |
clf.fit(data, label) | |
pre = clf.predict(data) | |
print(pre) | |
ok = 0; total = 0; | |
for idx, answer in enumerate(label): | |
p = pre[idx] | |
if p == answer: ok += 1 | |
total += 1 | |
print(ok, " : ", total, " : ", ok/total) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment