source: orange/Orange/doc/reference/warnings.htm @ 9671:a7b056375472

Revision 9671:a7b056375472, 2.9 KB checked in by anze <anze.staric@…>, 2 years ago (diff)

Moved orange to Orange (part 2)

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>Warnings</h1>
7<index name="warnings">
8
9<P>Orange defines three warning classes: <CODE>orange.Warning</CODE> is the base class, derived from it are <CODE>orange.KernelWarning</CODE> and <CODE>orange.AttributeWarning</CODE>.</p>
10
11<P>You will most often see the latter, which is issued by Orange-Python interface code when you set an attribute that didn't exist before; to it we shall dedicate a special section.
12The other warning <CODE>orange.KernelWarning</CODE> is issued by Orange kernel in various situations.</P>
13
14<H2>Fitering Warnings</H2>
15
16<P>Python has a mechanism of filters that allows you to decide what to do with warnings. Warnings can be either ignored completely, they can be reported the first time they occur, they can be reported always, or even treated as errors. Treatment of a particular warning can be specific for module, warning class and warning description. Read more about it in Python documentation on module <CODE>warnings</CODE>.</P>
17
18<H2>Attribute Warnings</H2>
19
20<P>Python allows to add attributes to class instances. This is a perfectly legal Python code that adds the attribute <CODE>test</CODE> to an instance of class <CODE>A</CODE>.</P>
21
22<XMP class="code">class A:
23    pass
24
25a = A()
26a.test = 12
27</XMP>
28
29<P>Such attributes can be quite useful, so Orange supports them as well (with exception of classes <CODE>Example</CODE> and <CODE>Value</CODE>, which are not derived from <CODE>Orange</CODE>). It is therefore OK to, for instance, store the number of misclassified examples to each leaf of decision tree to a new attribute, or add a comment to naive Bayesian learner:</P>
30
31<XMP class="code">bl = orange.BayesLearner()
32bl.comment = "Naive Bayesian learner with default parameters"
33</XMP>
34
35<P>This is, however, somewhat dangerous. Say that you want to set the method for estimation of conditional probabilities.</P>
36
37<XMP class="code">bl.conditionalEstimatrConstructor = \
38  orange.ConditionalProbabilityEstimatorConstructor_ByRows()
39</XMP>
40
41<P>It's a long line, so it's no wonder that we mistyped it:
42<CODE>conditionalEstimatorConstructor</CODE> misses an "o". But Orange thinks you wanted to assign a new attribute <CODE>conditionalEstimatrConstructor</CODE> to <CODE>bl</CODE>. <CODE>conditionalEstimatorConstructor</CODE> does not change, although the programmer thinks it has!</P>
43
44<P>The solution is to give warnings: you are free to set new attributes, such as <CODE>comment</CODE> (or <CODE>conditionalEstimatrConstructor</CODE>), but you'll get a warning the first time that certain attribute is set at certain place. Exception to this are modules whose name begin with <CODE>orng</CODE>. You can also disable the warnings in your code, if you dare:</p>
45
46<XMP class="code">import warnings
47warnings.filterwarnings("ignore", "", orange.AttributeWarning)
48</XMP>
49
50</BODY></HTML>
Note: See TracBrowser for help on using the repository browser.