In [1]:
import argparse
import numpy as np

from svm import weight_vector, find_support, find_slack
from sklearn.svm import SVC

from sklearn.model_selection import GridSearchCV
from sklearn.metrics import classification_report

In [2]:
class FoursAndNines:
    """
    Class to store MNIST data
    """

    def __init__(self, location):
        # You shouldn't have to modify this class, but you can if
        # you'd like.

        import pickle, gzip

        # Load the dataset
        f = gzip.open(location, 'rb')

        train_set, valid_set, test_set = pickle.load(f)

        self.x_train = train_set[0][np.where(np.logical_or( train_set[1]==4, train_set[1] == 9))[0],:]
        self.y_train = train_set[1][np.where(np.logical_or( train_set[1]==4, train_set[1] == 9))[0]]

        shuff = np.arange(self.x_train.shape[0])
        np.random.shuffle(shuff)
        self.x_train = self.x_train[shuff,:]
        self.y_train = self.y_train[shuff]

        self.x_valid = valid_set[0][np.where(np.logical_or( valid_set[1]==4, valid_set[1] == 9))[0],:]
        self.y_valid = valid_set[1][np.where(np.logical_or( valid_set[1]==4, valid_set[1] == 9))[0]]

        self.x_test  = test_set[0][np.where(np.logical_or( test_set[1]==4, test_set[1] == 9))[0],:]
        self.y_test  = test_set[1][np.where(np.logical_or( test_set[1]==4, test_set[1] == 9))[0]]

        f.close()

In [3]:
def mnist_digit_show(flatimage, outname=None):

    import matplotlib.pyplot as plt

    image = np.reshape(flatimage, (-1,28))

    plt.matshow(image, cmap=plt.cm.binary)
    plt.xticks([])
    plt.yticks([])
    if outname:
        plt.savefig(outname)
    else:
        plt.show()

In [4]:
#parser = argparse.ArgumentParser(description='SVM classifier options')
#parser.add_argument('--limit', type=int, default=-1,
#                    help="Restrict training to this many examples")
#args = parser.parse_args()


data = FoursAndNines("../data/mnist.pkl.gz")

In [6]:
# TODO: Use the Sklearn implementation of support vector machines to train a classifier to
# distinguish 4's from 9's (using the MNIST data from the KNN homework).
# Use scikit-learn's Grid Search (http://scikit-learn.org/stable/modules/grid_search.html) to help determine
# optimial hyperparameters for the given model (e.g. C for linear kernel, C and p for polynomial kernel, and C and gamma for RBF).
# Set the parameters by cross-validation
tuned_parameters = [{'kernel': ['rbf'], 'gamma': [1e-3, 1e-4],
                     'C': [1, 10, 100, 1000]},
                    {'kernel': ['linear'], 'C': [1, 10, 100, 1000]},
                    {'kernel': ['poly'], 'degree': [2, 3, 4]}]

scores = ['precision', 'recall']



for score in scores:
    print("# Tuning hyper-parameters for %s" % score)
    print()

    clf = GridSearchCV(SVC(), tuned_parameters, cv=5,
                       scoring='%s_macro' % score, n_jobs=2,
                       verbose=2)
    clf.fit(data.x_train, data.y_train)

    print("Best parameters set found on development set:")
    print()
    print(clf.best_params_)
    print()
    print("Grid scores on development set:")
    print()
    means = clf.cv_results_['mean_test_score']
    stds = clf.cv_results_['std_test_score']
    for mean, std, params in zip(means, stds, clf.cv_results_['params']):
        print("%0.3f (+/-%0.03f) for %r"
              % (mean, std * 2, params))
    print()

    print("Detailed classification report:")
    print()
    print("The model is trained on the full development set.")
    print("The scores are computed on the full evaluation set.")
    print()
    y_true, y_pred = data.y_test, clf.predict(data.x_test)
    print(classification_report(y_true, y_pred))
    print()

# -----------------------------------
# Plotting Examples
# -----------------------------------

# Display in on screen
mnist_digit_show(data.x_train[ 0,:])

# Plot image to file}
#mnist_digit_show(data.x_train[1,:], "mnistfig.png")


# Tuning hyper-parameters for precision

Fitting 5 folds for each of 15 candidates, totalling 75 fits
[CV] C=1, gamma=0.001, kernel=rbf ....................................
[CV] C=1, gamma=0.001, kernel=rbf ....................................
[CV] ..................... C=1, gamma=0.001, kernel=rbf, total=  23.2s
[CV] C=1, gamma=0.001, kernel=rbf ....................................
[CV] ..................... C=1, gamma=0.001, kernel=rbf, total=  23.3s
[CV] C=1, gamma=0.001, kernel=rbf ....................................
[CV] ..................... C=1, gamma=0.001, kernel=rbf, total=  22.0s
[CV] C=1, gamma=0.001, kernel=rbf ....................................
[CV] ..................... C=1, gamma=0.001, kernel=rbf, total=  22.0s
[CV] C=1, gamma=0.0001, kernel=rbf ...................................
[CV] ..................... C=1, gamma=0.001, kernel=rbf, total=  19.7s
[CV] C=1, gamma=0.0001, kernel=rbf ...................................
[CV] .................... C=1, gamma=0.0001, kernel=rbf, total=  44.2s
[CV] C=1, gamma=0.0001, kernel=rbf ...................................
[CV] .................... C=1, gamma=0.0001, kernel=rbf, total=  44.1s
[CV] C=1, gamma=0.0001, kernel=rbf ...................................
[CV] .................... C=1, gamma=0.0001, kernel=rbf, total=  44.1s
[CV] C=1, gamma=0.0001, kernel=rbf ...................................
[CV] .................... C=1, gamma=0.0001, kernel=rbf, total=  44.8s
[CV] C=10, gamma=0.001, kernel=rbf ...................................
[CV] .................... C=10, gamma=0.001, kernel=rbf, total=  10.3s
[CV] C=10, gamma=0.001, kernel=rbf ...................................
[CV] .................... C=10, gamma=0.001, kernel=rbf, total=  10.5s
[CV] C=10, gamma=0.001, kernel=rbf ...................................
[CV] .................... C=1, gamma=0.0001, kernel=rbf, total=  45.3s
[CV] C=10, gamma=0.001, kernel=rbf ...................................
[CV] .................... C=10, gamma=0.001, kernel=rbf, total=  10.5s
[CV] C=10, gamma=0.001, kernel=rbf ...................................
[CV] .................... C=10, gamma=0.001, kernel=rbf, total=  10.6s
[CV] C=10, gamma=0.0001, kernel=rbf ..................................
[CV] .................... C=10, gamma=0.001, kernel=rbf, total=  10.7s
[CV] C=10, gamma=0.0001, kernel=rbf ..................................
[CV] ................... C=10, gamma=0.0001, kernel=rbf, total=  19.5s
[CV] C=10, gamma=0.0001, kernel=rbf ..................................
[CV] ................... C=10, gamma=0.0001, kernel=rbf, total=  19.4s
[CV] C=10, gamma=0.0001, kernel=rbf ..................................
[CV] ................... C=10, gamma=0.0001, kernel=rbf, total=  19.3s
[CV] C=10, gamma=0.0001, kernel=rbf ..................................
[CV] ................... C=10, gamma=0.0001, kernel=rbf, total=  19.3s
[CV] C=100, gamma=0.001, kernel=rbf ..................................
[CV] ................... C=100, gamma=0.001, kernel=rbf, total=   7.9s
[CV] C=100, gamma=0.001, kernel=rbf ..................................
[CV] ................... C=10, gamma=0.0001, kernel=rbf, total=  19.7s
[CV] C=100, gamma=0.001, kernel=rbf ..................................
[CV] ................... C=100, gamma=0.001, kernel=rbf, total=   7.6s
[CV] C=100, gamma=0.001, kernel=rbf ..................................
[CV] ................... C=100, gamma=0.001, kernel=rbf, total=   8.1s
[CV] C=100, gamma=0.001, kernel=rbf ..................................
[CV] ................... C=100, gamma=0.001, kernel=rbf, total=   7.8s
[CV] C=100, gamma=0.0001, kernel=rbf .................................
[CV] ................... C=100, gamma=0.001, kernel=rbf, total=   7.8s
[CV] C=100, gamma=0.0001, kernel=rbf .................................
[CV] .................. C=100, gamma=0.0001, kernel=rbf, total=  10.6s
[CV] C=100, gamma=0.0001, kernel=rbf .................................
[CV] .................. C=100, gamma=0.0001, kernel=rbf, total=  10.8s
[CV] C=100, gamma=0.0001, kernel=rbf .................................
[CV] .................. C=100, gamma=0.0001, kernel=rbf, total=  10.6s
[CV] C=100, gamma=0.0001, kernel=rbf .................................
[CV] .................. C=100, gamma=0.0001, kernel=rbf, total=  10.9s
[CV] C=1000, gamma=0.001, kernel=rbf .................................
[CV] .................. C=100, gamma=0.0001, kernel=rbf, total=  10.8s
[CV] C=1000, gamma=0.001, kernel=rbf .................................
[CV] .................. C=1000, gamma=0.001, kernel=rbf, total=   7.8s
[CV] C=1000, gamma=0.001, kernel=rbf .................................
[CV] .................. C=1000, gamma=0.001, kernel=rbf, total=   7.7s
[CV] C=1000, gamma=0.001, kernel=rbf .................................
[CV] .................. C=1000, gamma=0.001, kernel=rbf, total=   7.9s
[CV] C=1000, gamma=0.001, kernel=rbf .................................
[CV] .................. C=1000, gamma=0.001, kernel=rbf, total=   7.9s
[CV] C=1000, gamma=0.0001, kernel=rbf ................................
[CV] .................. C=1000, gamma=0.001, kernel=rbf, total=   7.9s
[CV] C=1000, gamma=0.0001, kernel=rbf ................................
[CV] ................. C=1000, gamma=0.0001, kernel=rbf, total=   8.8s
[CV] C=1000, gamma=0.0001, kernel=rbf ................................
[CV] ................. C=1000, gamma=0.0001, kernel=rbf, total=   8.6s
[CV] C=1000, gamma=0.0001, kernel=rbf ................................
[Parallel(n_jobs=2)]: Done  37 tasks      | elapsed:  8.9min
[CV] ................. C=1000, gamma=0.0001, kernel=rbf, total=   9.2s
[CV] C=1000, gamma=0.0001, kernel=rbf ................................
[CV] ................. C=1000, gamma=0.0001, kernel=rbf, total=   8.7s
[CV] C=1, kernel=linear ..............................................
[CV] ................. C=1000, gamma=0.0001, kernel=rbf, total=   8.7s
[CV] C=1, kernel=linear ..............................................
[CV] ............................... C=1, kernel=linear, total=  10.1s
[CV] C=1, kernel=linear ..............................................
[CV] ............................... C=1, kernel=linear, total=  11.1s
[CV] C=1, kernel=linear ..............................................
[CV] ............................... C=1, kernel=linear, total=  10.2s
[CV] C=1, kernel=linear ..............................................
[CV] ............................... C=1, kernel=linear, total=  10.0s
[CV] C=10, kernel=linear .............................................
[CV] ............................... C=1, kernel=linear, total=   9.8s
[CV] C=10, kernel=linear .............................................
[CV] .............................. C=10, kernel=linear, total=  14.0s
[CV] C=10, kernel=linear .............................................
[CV] .............................. C=10, kernel=linear, total=  14.5s
[CV] C=10, kernel=linear .............................................
[CV] .............................. C=10, kernel=linear, total=  13.9s
[CV] C=10, kernel=linear .............................................
[CV] .............................. C=10, kernel=linear, total=  15.1s
[CV] C=100, kernel=linear ............................................
[CV] .............................. C=10, kernel=linear, total=  14.9s
[CV] C=100, kernel=linear ............................................
[CV] ............................. C=100, kernel=linear, total=  29.4s
[CV] C=100, kernel=linear ............................................
[CV] ............................. C=100, kernel=linear, total=  38.0s
[CV] C=100, kernel=linear ............................................
[CV] ............................. C=100, kernel=linear, total=  32.3s
[CV] C=100, kernel=linear ............................................
[CV] ............................. C=100, kernel=linear, total=  33.3s
[CV] C=1000, kernel=linear ...........................................
[CV] ............................. C=100, kernel=linear, total=  35.8s
[CV] C=1000, kernel=linear ...........................................
[CV] ............................ C=1000, kernel=linear, total= 1.6min
[CV] C=1000, kernel=linear ...........................................
[CV] ............................ C=1000, kernel=linear, total= 3.8min
[CV] C=1000, kernel=linear ...........................................
[CV] ............................ C=1000, kernel=linear, total= 3.2min
[CV] C=1000, kernel=linear ...........................................
[CV] ............................ C=1000, kernel=linear, total= 3.7min
[CV] degree=2, kernel=poly ...........................................
[CV] ............................ C=1000, kernel=linear, total= 2.9min
[CV] degree=2, kernel=poly ...........................................
[CV] ............................ degree=2, kernel=poly, total=  48.1s
[CV] degree=2, kernel=poly ...........................................
[CV] ............................ degree=2, kernel=poly, total=  48.1s
[CV] degree=2, kernel=poly ...........................................
[CV] ............................ degree=2, kernel=poly, total=  48.6s
[CV] degree=2, kernel=poly ...........................................
[CV] ............................ degree=2, kernel=poly, total=  48.4s
[CV] degree=3, kernel=poly ...........................................
[CV] ............................ degree=2, kernel=poly, total=  48.9s
[CV] degree=3, kernel=poly ...........................................
[CV] ............................ degree=3, kernel=poly, total= 1.1min
[CV] degree=3, kernel=poly ...........................................
[CV] ............................ degree=3, kernel=poly, total= 1.2min
[CV] degree=3, kernel=poly ...........................................
[CV] ............................ degree=3, kernel=poly, total= 1.1min
[CV] degree=3, kernel=poly ...........................................
[CV] ............................ degree=3, kernel=poly, total= 1.1min
[CV] degree=4, kernel=poly ...........................................
[CV] ............................ degree=3, kernel=poly, total= 1.1min
[CV] degree=4, kernel=poly ...........................................
/Users/brianmckean/anaconda2/envs/hwenv/lib/python3.6/site-packages/sklearn/metrics/classification.py:1135: UndefinedMetricWarning: Precision is ill-defined and being set to 0.0 in labels with no predicted samples.
  'precision', 'predicted', average, warn_for)
/Users/brianmckean/anaconda2/envs/hwenv/lib/python3.6/site-packages/sklearn/metrics/classification.py:1135: UndefinedMetricWarning: Precision is ill-defined and being set to 0.0 in labels with no predicted samples.
  'precision', 'predicted', average, warn_for)
[CV] ............................ degree=4, kernel=poly, total= 1.1min
[CV] degree=4, kernel=poly ...........................................
[CV] ............................ degree=4, kernel=poly, total= 1.2min
[CV] degree=4, kernel=poly ...........................................
/Users/brianmckean/anaconda2/envs/hwenv/lib/python3.6/site-packages/sklearn/metrics/classification.py:1135: UndefinedMetricWarning: Precision is ill-defined and being set to 0.0 in labels with no predicted samples.
  'precision', 'predicted', average, warn_for)
/Users/brianmckean/anaconda2/envs/hwenv/lib/python3.6/site-packages/sklearn/metrics/classification.py:1135: UndefinedMetricWarning: Precision is ill-defined and being set to 0.0 in labels with no predicted samples.
  'precision', 'predicted', average, warn_for)
[CV] ............................ degree=4, kernel=poly, total= 1.1min
[CV] degree=4, kernel=poly ...........................................
[CV] ............................ degree=4, kernel=poly, total= 1.1min
/Users/brianmckean/anaconda2/envs/hwenv/lib/python3.6/site-packages/sklearn/metrics/classification.py:1135: UndefinedMetricWarning: Precision is ill-defined and being set to 0.0 in labels with no predicted samples.
  'precision', 'predicted', average, warn_for)
[CV] ............................ degree=4, kernel=poly, total= 1.1min
[Parallel(n_jobs=2)]: Done  75 out of  75 | elapsed: 33.7min finished
Best parameters set found on development set:

{'C': 1000, 'gamma': 0.001, 'kernel': 'rbf'}

Grid scores on development set:

0.960 (+/-0.004) for {'C': 1, 'gamma': 0.001, 'kernel': 'rbf'}
0.938 (+/-0.008) for {'C': 1, 'gamma': 0.0001, 'kernel': 'rbf'}
0.972 (+/-0.003) for {'C': 10, 'gamma': 0.001, 'kernel': 'rbf'}
0.959 (+/-0.004) for {'C': 10, 'gamma': 0.0001, 'kernel': 'rbf'}
0.982 (+/-0.004) for {'C': 100, 'gamma': 0.001, 'kernel': 'rbf'}
0.968 (+/-0.004) for {'C': 100, 'gamma': 0.0001, 'kernel': 'rbf'}
0.987 (+/-0.004) for {'C': 1000, 'gamma': 0.001, 'kernel': 'rbf'}
0.971 (+/-0.006) for {'C': 1000, 'gamma': 0.0001, 'kernel': 'rbf'}
0.965 (+/-0.006) for {'C': 1, 'kernel': 'linear'}
0.959 (+/-0.010) for {'C': 10, 'kernel': 'linear'}
0.955 (+/-0.007) for {'C': 100, 'kernel': 'linear'}
0.948 (+/-0.014) for {'C': 1000, 'kernel': 'linear'}
0.948 (+/-0.006) for {'degree': 2, 'kernel': 'poly'}
0.758 (+/-0.002) for {'degree': 3, 'kernel': 'poly'}
0.253 (+/-0.000) for {'degree': 4, 'kernel': 'poly'}

Detailed classification report:

The model is trained on the full development set.
The scores are computed on the full evaluation set.

             precision    recall  f1-score   support

          4       0.99      0.98      0.99       982
          9       0.99      0.99      0.99      1009

avg / total       0.99      0.99      0.99      1991


# Tuning hyper-parameters for recall

Fitting 5 folds for each of 15 candidates, totalling 75 fits
[CV] C=1, gamma=0.001, kernel=rbf ....................................
[CV] C=1, gamma=0.001, kernel=rbf ....................................
[CV] ..................... C=1, gamma=0.001, kernel=rbf, total=  19.8s
[CV] C=1, gamma=0.001, kernel=rbf ....................................
[CV] ..................... C=1, gamma=0.001, kernel=rbf, total=  19.8s
[CV] C=1, gamma=0.001, kernel=rbf ....................................
[CV] ..................... C=1, gamma=0.001, kernel=rbf, total=  19.6s
[CV] C=1, gamma=0.001, kernel=rbf ....................................
[CV] ..................... C=1, gamma=0.001, kernel=rbf, total=  19.7s
[CV] C=1, gamma=0.0001, kernel=rbf ...................................
[CV] ..................... C=1, gamma=0.001, kernel=rbf, total=  19.6s
[CV] C=1, gamma=0.0001, kernel=rbf ...................................
[CV] .................... C=1, gamma=0.0001, kernel=rbf, total=  43.8s
[CV] C=1, gamma=0.0001, kernel=rbf ...................................
[CV] .................... C=1, gamma=0.0001, kernel=rbf, total=  43.7s
[CV] C=1, gamma=0.0001, kernel=rbf ...................................
[CV] .................... C=1, gamma=0.0001, kernel=rbf, total=  43.8s
[CV] C=1, gamma=0.0001, kernel=rbf ...................................
[CV] .................... C=1, gamma=0.0001, kernel=rbf, total=  43.9s
[CV] C=10, gamma=0.001, kernel=rbf ...................................
[CV] .................... C=10, gamma=0.001, kernel=rbf, total=  10.1s
[CV] C=10, gamma=0.001, kernel=rbf ...................................
[CV] .................... C=10, gamma=0.001, kernel=rbf, total=  10.0s
[CV] C=10, gamma=0.001, kernel=rbf ...................................
[CV] .................... C=1, gamma=0.0001, kernel=rbf, total=  44.5s
[CV] C=10, gamma=0.001, kernel=rbf ...................................
[CV] .................... C=10, gamma=0.001, kernel=rbf, total=  10.2s
[CV] C=10, gamma=0.001, kernel=rbf ...................................
[CV] .................... C=10, gamma=0.001, kernel=rbf, total=  10.3s
[CV] C=10, gamma=0.0001, kernel=rbf ..................................
[CV] .................... C=10, gamma=0.001, kernel=rbf, total=  10.4s
[CV] C=10, gamma=0.0001, kernel=rbf ..................................
[CV] ................... C=10, gamma=0.0001, kernel=rbf, total=  19.0s
[CV] C=10, gamma=0.0001, kernel=rbf ..................................
[CV] ................... C=10, gamma=0.0001, kernel=rbf, total=  19.6s
[CV] C=10, gamma=0.0001, kernel=rbf ..................................
[CV] ................... C=10, gamma=0.0001, kernel=rbf, total=  19.9s
[CV] C=10, gamma=0.0001, kernel=rbf ..................................
[CV] ................... C=10, gamma=0.0001, kernel=rbf, total=  19.2s
[CV] C=100, gamma=0.001, kernel=rbf ..................................
[CV] ................... C=100, gamma=0.001, kernel=rbf, total=   7.7s
[CV] C=100, gamma=0.001, kernel=rbf ..................................
[CV] ................... C=10, gamma=0.0001, kernel=rbf, total=  19.3s
[CV] C=100, gamma=0.001, kernel=rbf ..................................
[CV] ................... C=100, gamma=0.001, kernel=rbf, total=   7.3s
[CV] C=100, gamma=0.001, kernel=rbf ..................................
[CV] ................... C=100, gamma=0.001, kernel=rbf, total=   7.6s
[CV] C=100, gamma=0.001, kernel=rbf ..................................
[CV] ................... C=100, gamma=0.001, kernel=rbf, total=   7.6s
[CV] C=100, gamma=0.0001, kernel=rbf .................................
[CV] ................... C=100, gamma=0.001, kernel=rbf, total=   7.5s
[CV] C=100, gamma=0.0001, kernel=rbf .................................
[CV] .................. C=100, gamma=0.0001, kernel=rbf, total=  10.2s
[CV] C=100, gamma=0.0001, kernel=rbf .................................
[CV] .................. C=100, gamma=0.0001, kernel=rbf, total=  10.3s
[CV] C=100, gamma=0.0001, kernel=rbf .................................
[CV] .................. C=100, gamma=0.0001, kernel=rbf, total=  10.6s
[CV] C=100, gamma=0.0001, kernel=rbf .................................
[CV] .................. C=100, gamma=0.0001, kernel=rbf, total=  10.3s
[CV] C=1000, gamma=0.001, kernel=rbf .................................
[CV] .................. C=100, gamma=0.0001, kernel=rbf, total=  10.7s
[CV] C=1000, gamma=0.001, kernel=rbf .................................
[CV] .................. C=1000, gamma=0.001, kernel=rbf, total=   7.2s
[CV] C=1000, gamma=0.001, kernel=rbf .................................
[CV] .................. C=1000, gamma=0.001, kernel=rbf, total=   7.3s
[CV] C=1000, gamma=0.001, kernel=rbf .................................
[CV] .................. C=1000, gamma=0.001, kernel=rbf, total=   7.3s
[CV] C=1000, gamma=0.001, kernel=rbf .................................
[CV] .................. C=1000, gamma=0.001, kernel=rbf, total=   7.5s
[CV] C=1000, gamma=0.0001, kernel=rbf ................................
[CV] .................. C=1000, gamma=0.001, kernel=rbf, total=   7.8s
[CV] C=1000, gamma=0.0001, kernel=rbf ................................
[CV] ................. C=1000, gamma=0.0001, kernel=rbf, total=   8.4s
[CV] C=1000, gamma=0.0001, kernel=rbf ................................
[CV] ................. C=1000, gamma=0.0001, kernel=rbf, total=   8.2s
[CV] C=1000, gamma=0.0001, kernel=rbf ................................
[Parallel(n_jobs=2)]: Done  37 tasks      | elapsed:  8.6min
[CV] ................. C=1000, gamma=0.0001, kernel=rbf, total=   8.4s
[CV] C=1000, gamma=0.0001, kernel=rbf ................................
[CV] ................. C=1000, gamma=0.0001, kernel=rbf, total=   8.4s
[CV] C=1, kernel=linear ..............................................
[CV] ................. C=1000, gamma=0.0001, kernel=rbf, total=   8.5s
[CV] C=1, kernel=linear ..............................................
[CV] ............................... C=1, kernel=linear, total=   9.2s
[CV] C=1, kernel=linear ..............................................
[CV] ............................... C=1, kernel=linear, total=   9.6s
[CV] C=1, kernel=linear ..............................................
[CV] ............................... C=1, kernel=linear, total=   9.6s
[CV] C=1, kernel=linear ..............................................
[CV] ............................... C=1, kernel=linear, total=   9.6s
[CV] C=10, kernel=linear .............................................
[CV] ............................... C=1, kernel=linear, total=   9.4s
[CV] C=10, kernel=linear .............................................
[CV] .............................. C=10, kernel=linear, total=  13.6s
[CV] C=10, kernel=linear .............................................
[CV] .............................. C=10, kernel=linear, total=  14.2s
[CV] C=10, kernel=linear .............................................
[CV] .............................. C=10, kernel=linear, total=  13.8s
[CV] C=10, kernel=linear .............................................
[CV] .............................. C=10, kernel=linear, total=  14.1s
[CV] C=100, kernel=linear ............................................
[CV] .............................. C=10, kernel=linear, total=  13.4s
[CV] C=100, kernel=linear ............................................
[CV] ............................. C=100, kernel=linear, total=  28.7s
[CV] C=100, kernel=linear ............................................
[CV] ............................. C=100, kernel=linear, total=  38.0s
[CV] C=100, kernel=linear ............................................
[CV] ............................. C=100, kernel=linear, total=  32.4s
[CV] C=100, kernel=linear ............................................
[CV] ............................. C=100, kernel=linear, total=  32.9s
[CV] C=1000, kernel=linear ...........................................
[CV] ............................. C=100, kernel=linear, total=  35.5s
[CV] C=1000, kernel=linear ...........................................
[CV] ............................ C=1000, kernel=linear, total= 1.6min
[CV] C=1000, kernel=linear ...........................................
[CV] ............................ C=1000, kernel=linear, total= 3.8min
[CV] C=1000, kernel=linear ...........................................
[CV] ............................ C=1000, kernel=linear, total= 3.2min
[CV] C=1000, kernel=linear ...........................................
[CV] ............................ C=1000, kernel=linear, total= 3.7min
[CV] degree=2, kernel=poly ...........................................
[CV] ............................ C=1000, kernel=linear, total= 3.0min
[CV] degree=2, kernel=poly ...........................................
[CV] ............................ degree=2, kernel=poly, total=  48.0s
[CV] degree=2, kernel=poly ...........................................
[CV] ............................ degree=2, kernel=poly, total=  47.9s
[CV] degree=2, kernel=poly ...........................................
[CV] ............................ degree=2, kernel=poly, total=  48.9s
[CV] degree=2, kernel=poly ...........................................
[CV] ............................ degree=2, kernel=poly, total=  48.7s
[CV] degree=3, kernel=poly ...........................................
[CV] ............................ degree=2, kernel=poly, total=  48.8s
[CV] degree=3, kernel=poly ...........................................
[CV] ............................ degree=3, kernel=poly, total= 1.1min
[CV] degree=3, kernel=poly ...........................................
[CV] ............................ degree=3, kernel=poly, total= 1.1min
[CV] degree=3, kernel=poly ...........................................
[CV] ............................ degree=3, kernel=poly, total= 1.1min
[CV] degree=3, kernel=poly ...........................................
[CV] ............................ degree=3, kernel=poly, total= 1.1min
[CV] degree=4, kernel=poly ...........................................
[CV] ............................ degree=3, kernel=poly, total= 1.1min
[CV] degree=4, kernel=poly ...........................................
[CV] ............................ degree=4, kernel=poly, total= 1.1min
[CV] degree=4, kernel=poly ...........................................
[CV] ............................ degree=4, kernel=poly, total= 1.1min
[CV] degree=4, kernel=poly ...........................................
[CV] ............................ degree=4, kernel=poly, total= 1.2min
[CV] degree=4, kernel=poly ...........................................
[CV] ............................ degree=4, kernel=poly, total= 1.1min
[CV] ............................ degree=4, kernel=poly, total= 1.1min
[Parallel(n_jobs=2)]: Done  75 out of  75 | elapsed: 33.3min finished
Best parameters set found on development set:

{'C': 1000, 'gamma': 0.001, 'kernel': 'rbf'}

Grid scores on development set:

0.960 (+/-0.004) for {'C': 1, 'gamma': 0.001, 'kernel': 'rbf'}
0.937 (+/-0.008) for {'C': 1, 'gamma': 0.0001, 'kernel': 'rbf'}
0.972 (+/-0.003) for {'C': 10, 'gamma': 0.001, 'kernel': 'rbf'}
0.959 (+/-0.004) for {'C': 10, 'gamma': 0.0001, 'kernel': 'rbf'}
0.982 (+/-0.004) for {'C': 100, 'gamma': 0.001, 'kernel': 'rbf'}
0.968 (+/-0.004) for {'C': 100, 'gamma': 0.0001, 'kernel': 'rbf'}
0.987 (+/-0.004) for {'C': 1000, 'gamma': 0.001, 'kernel': 'rbf'}
0.971 (+/-0.006) for {'C': 1000, 'gamma': 0.0001, 'kernel': 'rbf'}
0.965 (+/-0.006) for {'C': 1, 'kernel': 'linear'}
0.959 (+/-0.010) for {'C': 10, 'kernel': 'linear'}
0.955 (+/-0.007) for {'C': 100, 'kernel': 'linear'}
0.948 (+/-0.014) for {'C': 1000, 'kernel': 'linear'}
0.947 (+/-0.006) for {'degree': 2, 'kernel': 'poly'}
0.519 (+/-0.006) for {'degree': 3, 'kernel': 'poly'}
0.500 (+/-0.000) for {'degree': 4, 'kernel': 'poly'}

Detailed classification report:

The model is trained on the full development set.
The scores are computed on the full evaluation set.

             precision    recall  f1-score   support

          4       0.99      0.98      0.99       982
          9       0.99      0.99      0.99      1009

avg / total       0.99      0.99      0.99      1991



In [ ]: