Created
February 23, 2024 19:57
-
-
Save isedgar/02db92ef698b6cdb3314785bf1809124 to your computer and use it in GitHub Desktop.
Unbeatable tic-tac-toe one-vs-one classifier (assuming the machine always starts in the upper left corner).
This file contains hidden or 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
import numpy as np | |
from sklearn.preprocessing import normalize | |
from sklearn.multiclass import OneVsOneClassifier as ovo | |
from sklearn.linear_model import Perceptron | |
X = np.array([[-1,0,0,0,0,0,0,0],[-1,-1,0,0,0,1,0,0],[-1,0,-1,0,0,1,0,0],[-1,-1,-1,0,0,1,0,1],[-1,0,-1,-1,0,1,0,1],[-1,0,-1,0,-1,1,0,1],[-1,0,-1,0,0,1,-1,1],[-1,0,0,-1,0,1,0,0],[-1,0,0,0,-1,1,0,0],[-1,0,0,0,0,1,-1,0],[-1,0,0,0,0,1,0,-1],[0,-1,0,0,0,0,0,0],[-1,-1,0,0,0,1,0,0],[0,-1,-1,0,0,1,0,0],[-1,-1,-1,0,0,1,0,1],[0,-1,-1,-1,0,1,0,1],[0,-1,-1,0,-1,1,0,1],[0,-1,-1,0,0,1,-1,1],[0,-1,0,-1,0,1,0,0],[0,-1,0,0,-1,1,0,0],[0,-1,0,0,0,1,-1,0],[0,-1,0,0,0,1,0,-1],[0,0,-1,0,0,0,0,0],[-1,1,-1,0,0,0,0,0],[-1,1,-1,1,-1,0,0,0],[-1,1,-1,1,0,-1,0,0],[-1,1,-1,1,0,0,-1,0],[-1,1,-1,1,0,0,0,-1],[0,1,-1,-1,0,0,0,0],[0,1,-1,0,-1,0,0,0],[0,1,-1,0,0,-1,0,0],[0,1,-1,0,0,0,-1,0],[0,1,-1,0,0,0,0,-1],[0,0,0,-1,0,0,0,0],[1,-1,0,-1,0,0,0,0],[1,-1,-1,-1,0,1,0,0],[1,-1,-1,-1,1,1,-1,0],[1,-1,-1,-1,1,1,0,-1],[1,-1,0,-1,-1,1,0,0],[1,-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7,3,6,3,3,2,2,2,2,1,3,7,7,7,5,0,0,0,0,0,0,5,4,7,6,2,2,2,1,1,1,1,1,1,3,7,7,7,5,0,0,0,0,0,1,7,3,4,3,3,0,0,0,0,0,1,3,7,7,7,5,0,0,0,0,0,1,5,3,2,3,3,0,0,0,0,0], dtype=np.int32) | |
X = normalize(X, norm='l2') | |
clf = ovo(Perceptron(tol=None, shuffle=False)).fit(X, y) | |
print(clf.score(X,y)) |
What is y here?
Labels (or classes)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What is y here?