Created
April 12, 2013 03:00
-
-
Save HaveF/5368979 to your computer and use it in GitHub Desktop.
1nn -- pure matlab
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| % ... 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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
although it only need 4 sec to run, the code may use lots of memory...