From 4d2c8d9545e17c2711e8571d27cdaac0a60ed547 Mon Sep 17 00:00:00 2001 From: aswanipranjal Date: Fri, 12 Jan 2018 11:55:48 +0530 Subject: [PATCH 1/2] added example for Decision Tree Learner --- learning.ipynb | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/learning.ipynb b/learning.ipynb index 86c84e475..63de59cbb 100644 --- a/learning.ipynb +++ b/learning.ipynb @@ -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, From 20b0da7603f30a31d2d4cf3692af8eae06740ee5 Mon Sep 17 00:00:00 2001 From: aswanipranjal Date: Fri, 12 Jan 2018 12:06:04 +0530 Subject: [PATCH 2/2] fixed docstring in learning.py and description in learning.ipynb --- learning.ipynb | 2 +- learning.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/learning.ipynb b/learning.ipynb index 63de59cbb..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", 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):