Skip to content

Instantly share code, notes, and snippets.

@HaveF
Created April 12, 2013 03:00
Show Gist options
  • Save HaveF/5368979 to your computer and use it in GitHub Desktop.
Save HaveF/5368979 to your computer and use it in GitHub Desktop.
1nn -- pure matlab
% ... Xtrain/Xtest/ytrain/ytest/ntest/
tic
% sum of squares term for speed
XtrainSOS = sum(Xtrain.^2,2);
XtestSOS = sum(Xtest.^2,2);
ypred = zeros(ntest,1);
% Classify
dst = sqDistance(Xtest(:,:),Xtrain,XtestSOS(:,:),XtrainSOS);
[~,closest] = min(dst,[],2);
ypred = ytrain(closest);
% Report
errorRate = mean(ypred ~= ytest);
fprintf('Error Rate: %.2f%%\n',100*errorRate);
t = toc; fprintf('Total Time: %.2f seconds\n',t);
@HaveF
Copy link
Author

HaveF commented Apr 12, 2013

although it only need 4 sec to run, the code may use lots of memory...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment