Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Added Decision Tree Learner example to learning.ipynb. #686

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 38 additions & 2 deletions learning.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -1072,6 +1072,42 @@
"</ol>"
]
},
{
"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": {},
Expand Down Expand Up @@ -1760,7 +1796,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.3"
"version": "3.6.3"
}
},
"nbformat": 4,
Expand Down
2 changes: 1 addition & 1 deletion learning.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down