from tensorflow.keras.datasets import mnist
from sklearn.svm import SVC
from sklearn.metrics import accuracy_score
from sklearn.model_selection import train_test_split
import matplotlib.pyplot as plt
import numpy as np
(X_train, y_train), (X_test, y_test) = mnist.load_data()
X_train.shape
X_train = X_train.reshape(X_train.shape[0], 784)
X_test = X_test.reshape(X_test.shape[0], 784)
X_train1, X_train_2, y_train1, y_train2 = train_test_split(X_train, y_train, test_size=0.8)
X_train1.shape
svm = SVC(kernel='poly', degree=2, C=1)
svm.fit(X_train1, y_train1)
print(svm.score(X_test, y_test))
y_pred = svm.predict(X_test)
print(f'Accuracy: {accuracy_score(y_pred, y_test)}')
i = 132
plt.imshow(X_train1[i].reshape(28,28), cmap='gray')
print(y_train1[i])
svm.predict(np.array([X_train1[i]]))[0]