source: orange/orange/doc/reference/knnlearner.py @ 6538:a5f65d7f0b2c

Revision 6538:a5f65d7f0b2c, 811 bytes checked in by Mitar <Mitar@…>, 4 years ago (diff)

Made XPM version of the icon 32x32.

Line 
1# Description: Shows how to use the nearest-neighbour learning
2# Category:    learning
3# Classes:     kNNLearner, kNNClassifier, ExamplesDistance, ExamplesDistanceConstructor
4# Uses:        iris
5# Referenced:  kNNLearner.htm
6
7import orange, orngTest, orngStat
8data = orange.ExampleTable("iris")
9
10rndind = orange.MakeRandomIndices2(data, p0=0.8)
11train = data.select(rndind, 0)
12test = data.select(rndind, 1)
13
14knn = orange.kNNLearner(train, k=10)
15for i in range(5):
16    example = test.randomexample()
17    print example.getclass(), knn(example)
18
19print "\n\n"
20data = orange.ExampleTable("iris")
21knn = orange.kNNLearner()
22knn.k = 10
23knn.distanceConstructor = orange.ExamplesDistanceConstructor_Hamming()
24knn = knn(train)
25for i in range(5):
26    example = test.randomexample()
27    print example.getclass(), knn(example)
Note: See TracBrowser for help on using the repository browser.