<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Testing the usefulness of FFT for digit recognition
Inital classification approach taken from Scikit-learn Hand-written digit recognizion example using support vector machine calassifier http
Step1:  Fetching the MNIST dataset
Step2:  It's 70000 examples of handwritten digits of size 28x28 pixels, labeled from 0 to 9.
The data is ordered and needs to be shuffled
Step3:  Pick the first 15 images for visualization
Step4:  Creating a support vector classifier
Step5:  Apply learning on the first half of the digits
Step6:  Predictions
Step7:  Scikit-learn SVM doesn't seem to be of the fastest kind, need to check parameters.
* Doesn't appear to be memory problem that it stalls at 35000 samples in this case. 10000 samples was in a minute or few.
* May try more optimized learning approach.
<ASSISTANT_TASK:>
Python Code:
import matplotlib.pyplot as plt
import numpy as np
%matplotlib notebook
from sklearn import datasets, svm, metrics, utils
Explanation: Testing the usefulness of FFT for digit recognition
Inital classification approach taken from Scikit-learn Hand-written digit recognizion example using support vector machine calassifier http://scikit-learn.org/stable/auto_examples/classification/plot_digits_classification.html applied for MNIST dataset.
End of explanation
from sklearn.datasets import fetch_mldata
mnist = fetch_mldata('MNIST original', data_home='./data')
Explanation: Fetching the MNIST dataset
End of explanation
mnist.data, mnist.target = utils.shuffle(mnist.data, mnist.target)
Explanation: It's 70000 examples of handwritten digits of size 28x28 pixels, labeled from 0 to 9.
The data is ordered and needs to be shuffled
End of explanation
n_samples = len(mnist.data)
fig = plt.figure()
for i in range(15):
    img = mnist.data[i].reshape(28, 28)
    
    ax = fig.add_subplot(3, 5, i+1)
    ax.axis('off')
    ax.imshow(img, cmap=plt.cm.gray, interpolation='nearest')
    ax.set_title('# {}'.format(i))
    
Explanation: Pick the first 15 images for visualization
End of explanation
# gamma = 0.001, which was in the example for 8x8 images, seems to 
# heavily overfit 28x28 MNIST data with N=10000 samples, predicts only 1
#classifier = svm.SVC(gamma=0.001)
# TODO: There must be a bug!
classifier = svm.SVC()
Explanation: Creating a support vector classifier
End of explanation
N = n_samples//2
N = 10000
classifier.fit(mnist.data[:N], mnist.target[:N])
Explanation: Apply learning on the first half of the digits
End of explanation
expected = mnist.target[N:2*N]
predicted = classifier.predict(mnist.data[N:2*N])
Explanation: Predictions
End of explanation
print("Classification report for classifier %s:\n%s\n"
      % (classifier, metrics.classification_report(expected, predicted)))
print("Confusion matrix:\n%s" % metrics.confusion_matrix(expected, predicted))
expected, predicted
np.unique(predicted)
expected = mnist.target[:N]
predicted = classifier.predict(mnist.data[:N])
mnist.data[N:2*N].shape
Explanation: Scikit-learn SVM doesn't seem to be of the fastest kind, need to check parameters.
* Doesn't appear to be memory problem that it stalls at 35000 samples in this case. 10000 samples was in a minute or few.
* May try more optimized learning approach.
End of explanation
<END_TASK>