source: orange/docs/reference/rst/code/ensemble-forest-measure.py @ 9638:eb3af38491f2

Revision 9638:eb3af38491f2, 1014 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: Demonstrates the use of random forests from Orange.ensemble.forest module
2# Category:    classification, ensembles
3# Classes:     RandomForestLearner
4# Uses:        iris.tab
5# Referenced:  orngEnsemble.htm
6
7import Orange
8import random
9
10files = [ "iris.tab" ]
11
12for fn in files:
13    print "\nDATA:" + fn + "\n"
14    iris = Orange.data.Table(fn)
15
16    measure = Orange.ensemble.forest.ScoreFeature(trees=100)
17
18    #call by attribute index
19    imp0 = measure(0, iris) 
20    #call by orange.Variable
21    imp1 = measure(iris.domain.attributes[1], iris)
22    print "first: %0.2f, second: %0.2f\n" % (imp0, imp1)
23
24    print "different random seed"
25    measure = Orange.ensemble.forest.ScoreFeature(trees=100, 
26            rand=random.Random(10))
27
28    imp0 = measure(0, iris)
29    imp1 = measure(iris.domain.attributes[1], iris)
30    print "first: %0.2f, second: %0.2f\n" % (imp0, imp1)
31
32    print "All importances:"
33    for at in iris.domain.attributes:
34        print "%15s: %6.2f" % (at.name, measure(at, iris))
Note: See TracBrowser for help on using the repository browser.