import numpy as np from sklearn import svm mnist = np.load('mnist.npz') x_train = mnist['x_train'][mnist['y_train']<=1]/255. y_train = mnist['y_train'][mnist['y_train']<=1] x_test = mnist['x_test'][mnist['y_test']<=1]/255. y_test = mnist['y_test'][mnist['y_test']<=1] x_train = np.array([[img.mean(),img[10:18,11:17].mean()] for img in x_train]) x_test = np.array([[img.mean(),img[10:18,11:17].mean()] for img in x_test]) clf = svm.SVC(kernel='linear', C=1.0) clf.fit(x_train, y_train) s_train = clf.score(x_train, y_train) s_test = clf.score(x_test, y_test) print('Performance (training):', s_train) print('Performance (testing):', s_test)