import numpy as np
import matplotlib.pyplot as plt

GRAY_SCALE_RANGE = 255

import pickle

data_filename = 'data_deskewed.pkl'
print('Loading data from file \'' + data_filename + '\' ...')
with open(data_filename, 'rb') as f:
    train_labels = pickle.load(f)
    train_images = pickle.load(f)
    test_labels = pickle.load(f)
    test_images = pickle.load(f)
    num_pixel = pickle.load(f)
print('Data loading complete.')

train_images = np.array(train_images)
train_images.resize(train_images.size // num_pixel, num_pixel)
test_images = np.array(test_images)
test_images.resize(test_images.size // num_pixel, num_pixel)
test_labels = np.array(test_labels)
train_labels = np.array(train_labels)

train_labels_ten = np.zeros((train_labels.size, 10))
test_labels_ten = np.zeros((test_labels.size, 10))
for i in range(10):
    train_labels_ten[:, i] = train_labels == i
    test_labels_ten[:, i] = test_labels == i

## normalization
train_images = train_images / GRAY_SCALE_RANGE
test_images = test_images / GRAY_SCALE_RANGE


@@ -694,331 +694,459 @@
 s)%0A%0A
-train_labels_ten = np.zeros((train_labels.size, 10))%0Atest_labels_ten = np.zeros((test_labels.size, 10))%0Afor i in range(10):%0A    train_labels_ten%5B:, i%5D = train_labels == i%0A    test_labels_ten%5B:, i%5D = test_labels == i%0A%0A## normalization%0Atrain_images = train_images / GRAY_SCALE_RANGE%0Atest_images = test_images / GRAY_SCALE_RANGE%0A%0A
+## normalization%0Atrain_images = train_images / GRAY_SCALE_RANGE%0Atest_images = test_images / GRAY_SCALE_RANGE%0A%0Afrom sklearn import svm, metrics%0A%0Aclf = svm.SVC(gamma = 0.001)%0A%0Aclf.fit(train_images, train_labels)%0A%0Aprediction = clf.predict(test_images)%0A%0Aprint(%22Classification report for classifier %25s:%5Cn%25s%5Cn%22%0A%09  %25 (clf, metrics.classification_report(test_labels, prediction)))%0Aprint(%22Confusion matrix:%5Cn%25s%22 %25 metrics.confusion_matrix(test_labels, prediction))

Modify svm