% Classification of handwritten digits % 18th Machine Learning Summer School % % Author: Ruben Martinez-Cantin % clear all, close all seed = 943; randn('seed',seed), rand('seed',seed) % If you can work with more digits, you can download the full datasets % from Sam Roweis website http://cs.nyu.edu/~roweis/data.html load mnist_0to2; % Select training and testing sets % We assume binary classification digit0 = +1 / others = -1 trainset = [train0(1:1000,:); train1(1:400,:); train2(1:400,:)]; ytr = [ones(1000,1); -ones(800,1)]; testset = [test0(1:500,:); test1(1:200,:); test2(1:200,:)]; yte = [ones(500,1); -ones(400,1)]; % MATLAB only knows how to do operations with type "double" but the data is % stored as "uint8". This transforms uint8 -> double xtrain = mat2gray(trainset); xtest = mat2gray(testset); % Dimensionality reduction using PCA nPCAComp = 16; [xtr,v,m] = reduceusingpca(xtrain,nPCAComp); xte = project2pca(xtest,v,m); % Set up the GP % TODO: Modify these lines %--------------------------------------------------------------------------cov = hyp0.cov = mean = hyp0.mean = lik = hyp0.lik = inf = %-------------------------------------------------------------------------- % Classify Ncg = 50; % number of conjugate gradient steps hyp = minimize(hyp0,'gp', -Ncg, inf, mean, cov, lik, xtr, ytr); % opt hypers [ymu, ys2] = gp(hyp, inf, mean, cov, lik, xtr, ytr, xte); % predict y = 2*[ymu>0]-1; fprintf(1,'Classification results\n'); fprintf(1,'%2.2f %% success rate\n',sum(y==yte) / length(yte)*100);