source: orange/docs/reference/rst/code/knnlearner.py @ 9724:318e91106d47

Revision 9724:318e91106d47, 901 bytes checked in by markotoplak, 2 years ago (diff)

Renames in Orange.distance.

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
8iris = Orange.data.Table("iris")
9
10print "Testing using euclidean distance"
11rndind = Orange.core.MakeRandomIndices2(iris, p0=0.8)
12train = iris.select(rndind, 0)
13test = iris.select(rndind, 1)
14
15knn = Orange.classification.knn.kNNLearner(train, k=10)
16for i in range(5):
17    instance = test.random_instance()
18    print instance.getclass(), knn(instance)
19
20print "\n"
21print "Testing using hamming distance"
22iris = Orange.data.Table("iris")
23knn = Orange.classification.knn.kNNLearner()
24knn.k = 10
25knn.distance_constructor = Orange.distance.Hamming()
26knn = knn(train)
27for i in range(5):
28    instance = test.random_instance()
29    print instance.getclass(), knn(instance)
Note: See TracBrowser for help on using the repository browser.