diff --git a/learning.ipynb b/learning.ipynb index 86c84e475..16bb4bd6b 100644 --- a/learning.ipynb +++ b/learning.ipynb @@ -124,7 +124,7 @@ "\n", "* **examples**: Holds the items of the dataset. Each item is a list of values.\n", "\n", - "* **attrs**: The indexes of the features (by default in the range of [0,f), where *f* is the number of features. For example, `item[i]` returns the feature at index *i* of *item*.\n", + "* **attrs**: The indexes of the features (by default in the range of [0,f), where *f* is the number of features). For example, `item[i]` returns the feature at index *i* of *item*.\n", "\n", "* **attrnames**: An optional list with attribute names. For example, `item[s]`, where *s* is a feature name, returns the feature of name *s* in *item*.\n", "\n", @@ -1072,6 +1072,42 @@ "" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Example\n", + "\n", + "We will now use the Decision Tree Learner to classify a sample with values: 5.1, 3.0, 1.1, 0.1." + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "setosa\n" + ] + } + ], + "source": [ + "iris = DataSet(name=\"iris\")\n", + "\n", + "DTL = DecisionTreeLearner(iris)\n", + "print(DTL([5.1, 3.0, 1.1, 0.1]))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "As expected, the Decision Tree learner classifies the sample as \"setosa\" as seen in the previous section." + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -1760,7 +1796,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.5.3" + "version": "3.6.3" } }, "nbformat": 4, diff --git a/learning.py b/learning.py index f5bc5d835..0d3d3b110 100644 --- a/learning.py +++ b/learning.py @@ -542,7 +542,7 @@ def plurality_value(examples): return DecisionLeaf(popular) def count(attr, val, examples): - """Count the number of examples that have attr = val.""" + """Count the number of examples that have example[attr] = val.""" return sum(e[attr] == val for e in examples) def all_same_class(examples):