Drexel dragonThe Math ForumDonate to the Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.

Math Forum » Discussions » Software » comp.soft-sys.math.mathematica

Topic: Using Nearest function
Replies: 0  

Advanced Search

Back to Topic List Back to Topic List  
Dário Abdulrehman

Posts: 8
Registered: 5/26/10
Using Nearest function
Posted: Jun 7, 2010 8:06 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

This is my first attempt at writing Mathematica code but I am getting
strange results which are probably due to some bug I cannot detect.

This code creates a test set with 2 classes and size 1000 from a Bivariate
Gaussian distribution then creates 6 training sets with 2 classes and sizes
10^i, i = 1..6.

Then I run the Nearest neighbor algorithm on each train set and test set and
compute the error rate.

However, as you can see from the table at the end, I get error rates that
don't make much sense. I might as well flip a coin instead of running the
Unfortunately I cannot spot the bug in the code.

(* Code *)


m = 6;
testSize = 1000;

MN1=MultinormalDistribution[{0.5,0.5},(1 0
0 1

MN2=MultinormalDistribution[{-0.5,-0.5},(1 0
0 1




testSet = RandomVector[testSize];
trainingSets=Map[Function[x,RandomVector[x]],NestList[10 #&,10,m-1]];

classOf[i_] = If[i<=(testSize/2),1,2];



m 10 100 1000 10000 100000 1000000
error rate 0.5 0.5 0.322 0.484 0.499 0.501

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum 1994-2015. All Rights Reserved.