source: orange/docs/reference/rst/code/knnlearner.py @ 9638:eb3af38491f2

Revision 9638:eb3af38491f2, 919 bytes checked in by umek@…, 2 years ago (diff)

Changed table to data or name of the data set.

For example - instead of

table = Orange.data.Table("housing")

is changed to

housing = Orange.data.Table("housing")

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.randomexample()
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.distanceConstructor = Orange.core.ExamplesDistanceConstructor_Hamming()
26knn = knn(train)
27for i in range(5):
28    instance = test.randomexample()
29    print instance.getclass(), knn(instance)
Note: See TracBrowser for help on using the repository browser.