source: orange/orange/doc/reference/RandomClassifier.htm @ 6538:a5f65d7f0b2c

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

Made XPM version of the icon 32x32.

Line 
1<html> <HEAD>
2<LINK REL=StyleSheet HREF="../style.css" TYPE="text/css">
3<LINK REL=StyleSheet HREF="style-print.css" TYPE="text/css" MEDIA=print>
4</HEAD> <body>
5
6<h1>Random Classifier</h1>
7<index name="classifiers+random classifier">
8
9<P>Random classifier (class <code><INDEX name="classes/RandomClassifier">RandomClassifier</code>)disregards the examples and returns random predictions. Curious enough though, the classifier will always predict the same class for the same example. Predictions can be distributed by the prescribed distribution.</P>
10
11<P class=section>Attributes</P>
12<DL class=attributes>
13<DT>probabilites</DT>
14<DD>Distribution of probabilities for the classifier.</DD>
15</DL>
16
17<P>To verify this miraculous classifier, we shall classify the first ten examples from lenses dataset for three times.</P>
18
19<p class="header"><A href="random_classifier.py">random_classifier.py</a>
20(uses <a href="lenses.tab">lenses.tab</a>)</p>
21<XMP class=code>import orange, orngTest, orngStat
22
23data = orange.ExampleTable("lenses")
24
25rc = orange.RandomClassifier()
26rc.classVar = data.domain.classVar
27rc.probabilities = [0.5, 0.3, 0.2]
28
29for i in range(3):
30    for ex in data[:5]:
31        print ex, rc(ex)
32    print
33</XMP>
34
35<P>The script always prints</P>
36
37<XMP class=code>['young', 'myope', 'no', 'reduced', 'none'] none
38['young', 'myope', 'no', 'normal', 'soft'] soft
39['young', 'myope', 'yes', 'reduced', 'none'] none
40['young', 'myope', 'yes', 'normal', 'hard'] soft
41['young', 'hypermetrope', 'no', 'reduced', 'none'] none
42</XMP>
43
44<P>Setting <CODE>classVar</CODE> is needed for nicer output. Remove it and see what happens.</p>
45
46<P>OK, how does this really work? Random classifier computes the hash value of example (equivalent to calling <CODE>hash(ex)</CODE>, where <CODE>hash</CODE> is a Python's built-in function), masks it by <CODE>0x7fffffff</CODE> and divides it by <CODE>0x7fffffff</CODE> to get a floating point number between 0 and 1. This value's position in the distribution determines the class. In our example, random values below 0.5 give the first class, those between 0.5 and 0.8 give the second and the rest give the third.</P>
47
48<h1>Random Learner</h1>
49
50<P><code>RandomLearner</code> returns the above classifier.</P>
51
52<P class=section>Attributes</P>
53<DL class=attributes>
54<DT>probabilites</DT>
55<DD>Distribution of probabilities for the classifier. If not given, the learner will use the class distribution from the training data.</DD>
56</DL>
57
58</BODY></HTML>
Note: See TracBrowser for help on using the repository browser.