Skip to content

Commit 9c6ac61

Browse files
authored
Merge pull request #1564 from janezd/cn2-documentation
CN2: simplify documentation
2 parents 325cad0 + ef6da6a commit 9c6ac61

File tree

5 files changed

+21
-64
lines changed

5 files changed

+21
-64
lines changed

Orange/classification/rules.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
"""
2+
Induction of rules works by finding a rule that covers some learning instances,
3+
removing these instances, and repeating this until all instances are covered.
4+
Rules are scored by heuristics such as impurity of class distribution of
5+
covered instances. The module includes common rule-learning algorithms,
6+
and allows for replacing rule search strategies, scoring and other
7+
components.
8+
"""
9+
110
import operator
211
from copy import copy
312
from hashlib import sha1
@@ -1287,16 +1296,16 @@ def predict(self, X):
12871296

12881297
class CN2UnorderedLearner(_RuleLearner):
12891298
"""
1290-
Unordered CN2 inducer that constructs a set of unordered rules. To
1291-
evaluate found hypotheses, Laplace accuracy measure is used. Returns
1292-
a CN2UnorderedClassifier if called with data.
1299+
Construct a set of unordered rules.
12931300
1294-
Notes
1295-
-----
1296-
Rules are learnt for each class (target class) individually, in
1297-
regard to the original learning data. When a rule has been found,
1298-
only covered examples of that class are removed. This is because now
1299-
each rule must independently stand against all negatives.
1301+
Rules are learnt for each class individually and scored
1302+
by the relative frequency of the class corrected by the Laplace correction.
1303+
After adding a rule, only the covered examples of that class are removed.
1304+
1305+
The code below loads the *iris* data set (four continuous attributes
1306+
and a discrete class) and fits the learner.
1307+
1308+
.. literalinclude:: code/classification-cn2ruleinduction1.py
13001309
13011310
References
13021311
----------

doc/data-mining-library/source/reference/classification.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ Elliptic Envelope
176176
CN2 Rule Induction
177177
------------------
178178

179+
.. automodule:: Orange.classification.rules
180+
179181
.. autoclass:: CN2Learner
180182
:members:
181183

doc/data-mining-library/source/tutorial/code/classification-cn2ruleinduction1.py renamed to doc/data-mining-library/source/reference/code/classification-cn2ruleinduction1.py

File renamed without changes.

doc/data-mining-library/source/tutorial/classification.rst

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -136,57 +136,3 @@ Logistic regression wins in area under ROC curve::
136136
tree knn logreg
137137
Accuracy 0.79 0.47 0.78
138138
AUC 0.68 0.56 0.70
139-
140-
141-
Rule induction
142-
--------------
143-
144-
To induce rules from examples, separate and conquer strategy is applied.
145-
In essence, learning instances are covered and removed following a
146-
chosen rule. The process is repeated while learning instances remain. To
147-
evaluate found hypotheses and to choose the best rule in each iteration,
148-
search heuristics are used (primarily, rule class distribution is the
149-
decisive determinant). The over-fitting of noisy data is avoided by
150-
preferring simpler, shorter rules even if the accuracy of more complex
151-
rules is higher.
152-
153-
The use of the created module is straightforward. New rule induction
154-
algorithms can be easily introduced, by either utilising predefined
155-
components or developing new ones (these include various search
156-
algorithms, search strategies, evaluators, and others). Several
157-
well-known rule induction algorithms have already been included.
158-
159-
Unordered CN2
160-
+++++++++++++
161-
162-
Unordered CN2 inducer (:any:`CN2UnorderedLearner`) constructs a set of
163-
unordered rules. Rules are learnt for each class individually, in regard
164-
to the original learning data. To evaluate found hypotheses, Laplace
165-
accuracy measure is used. Returns a CN2UnorderedClassifier if called
166-
with data.
167-
168-
The code below loads the *iris* data set (four continuous attributes
169-
and a discrete class) and fits the learner.
170-
171-
.. literalinclude:: code/classification-cn2ruleinduction1.py
172-
173-
Having first initialised the learner, we then control the algorithm by
174-
modifying its parameters. The underlying components are available to us
175-
by accessing the rule finder. The search algorithm can additionally be
176-
constrained by forwarding base rules upon learner initialization (see
177-
code reference).
178-
179-
The classifier is used to predict data instances.
180-
181-
>>> classifier(data.X[50:55])
182-
[1 1 0 1 1]
183-
184-
Induced rules can be quickly reviewed and interpreted. They are each of
185-
the form "if cond then predict class". That is, a conjunction of
186-
selectors followed by the predicted class.
187-
188-
>>> for rule in classifier.rule_list[:3]:
189-
>>> print(rule, rule.curr_class_dist.tolist())
190-
IF petal length<=3.0 AND sepal width>=2.9 THEN iris=Iris-setosa [49, 0, 0]
191-
IF petal length>=3.0 AND petal length<=4.8 THEN iris=Iris-versicolor [0, 46, 3]
192-
IF petal width>=1.8 AND petal length>=4.9 THEN iris=Iris-virginica [0, 0, 43]

doc/visual-programming/source/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ Visualize
6161
widgets/visualize/sievediagram
6262
widgets/visualize/pythagoreantree
6363
widgets/visualize/pythagoreanforest
64+
widgets/classify/cn2ruleviewer
6465

6566

6667
Classify
@@ -80,7 +81,6 @@ Classify
8081
widgets/classify/saveclassifier
8182
widgets/classify/svm
8283
widgets/classify/cn2ruleinduction
83-
widgets/classify/cn2ruleviewer
8484

8585

8686
Regression

0 commit comments

Comments
 (0)