source: orange/Orange/testing/regression/tests_20/reference_knnlearner.py @ 9952:986e9cd806f4

Revision 9952:986e9cd806f4, 811 bytes checked in by Miha Stajdohar <miha.stajdohar@…>, 2 years ago (diff)

Tests moved and renamed from orange 20.

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.