emel v0.3.0 Emel.Ml.DecisionTree View Source

Uses a decision tree to go from observations about an item (represented in the branches) to conclusions about the item’s discrete target value (represented in the leaves).

Link to this section Summary

Functions

Returns the function that classifies an item by using the ID3 Algorithm

The expanded decision tree built with the ID3 Algorithm for a dataset with discrete attributes

Link to this section Functions

Link to this function classifier(dataset, discrete_attributes, class) View Source

Returns the function that classifies an item by using the ID3 Algorithm.

Examples

iex> f = Emel.Ml.DecisionTree.classifier([
...>         %{risk: "high", collateral: "none", income: "low", debt: "high", credit_history: "bad"},
...>         %{risk: "high", collateral: "none", income: "moderate", debt: "high", credit_history: "unknown"},
...>         %{risk: "moderate", collateral: "none", income: "moderate", debt: "low", credit_history: "unknown"},
...>         %{risk: "high", collateral: "none", income: "low", debt: "low", credit_history: "unknown"},
...>         %{risk: "low", collateral: "none", income: "high", debt: "low", credit_history: "unknown"},
...>         %{risk: "low", collateral: "adequate", income: "high", debt: "low", credit_history: "unknown"},
...>         %{risk: "high", collateral: "none", income: "low", debt: "low", credit_history: "bad"},
...>         %{risk: "moderate", collateral: "adequate", income: "high", debt: "low", credit_history: "bad"},
...>         %{risk: "low", collateral: "none", income: "high", debt: "low", credit_history: "good"},
...>         %{risk: "low", collateral: "adequate", income: "high", debt: "high", credit_history: "good"},
...>         %{risk: "high", collateral: "none", income: "low", debt: "high", credit_history: "good"},
...>         %{risk: "moderate", collateral: "none", income: "moderate", debt: "high", credit_history: "good"},
...>         %{risk: "low", collateral: "none", income: "high", debt: "high", credit_history: "good"},
...>         %{risk: "high", collateral: "none", income: "moderate", debt: "high", credit_history: "bad"}
...>    ], [:collateral, :income, :debt, :credit_history], :risk)
...> f.(%{collateral: "none", income: "high", debt: "low", credit_history: "good"})
"low"
Link to this function decision_tree(dataset, class, attributes) View Source

The expanded decision tree built with the ID3 Algorithm for a dataset with discrete attributes.

Examples

iex> Emel.Ml.DecisionTree.decision_tree([
...>         %{outlook: "Sunny", temperature: "Hot", humidity: "High", wind: "Weak", decision: "No"},
...>         %{outlook: "Sunny", temperature: "Hot", humidity: "High", wind: "Strong", decision: "No"},
...>         %{outlook: "Overcast", temperature: "Hot", humidity: "High", wind: "Weak", decision: "Yes"},
...>         %{outlook: "Rain", temperature: "Mild", humidity: "High", wind: "Weak", decision: "Yes"},
...>         %{outlook: "Rain", temperature: "Cool", humidity: "Normal", wind: "Weak", decision: "Yes"},
...>         %{outlook: "Rain", temperature: "Cool", humidity: "Normal", wind: "Strong", decision: "No"},
...>         %{outlook: "Overcast", temperature: "Cool", humidity: "Normal", wind: "Strong", decision: "Yes"},
...>         %{outlook: "Sunny", temperature: "Mild", humidity: "High", wind: "Weak", decision: "No"},
...>         %{outlook: "Sunny", temperature: "Cool", humidity: "Normal", wind: "Weak", decision: "Yes"},
...>         %{outlook: "Rain", temperature: "Mild", humidity: "Normal", wind: "Weak", decision: "Yes"},
...>         %{outlook: "Sunny", temperature: "Mild", humidity: "Normal", wind: "Strong", decision: "Yes"},
...>         %{outlook: "Overcast", temperature: "Mild", humidity: "High", wind: "Strong", decision: "Yes"},
...>         %{outlook: "Overcast", temperature: "Hot", humidity: "Normal", wind: "Weak", decision: "Yes"},
...>         %{outlook: "Rain", temperature: "Mild", humidity: "High", wind: "Strong", decision: "No"}
...>    ], :decision, [:outlook, :temperature, :humidity, :wind])
[
  [%{outlook: "Overcast"}, [%{decision: "Yes"}]],
  [
    %{outlook: "Rain"},
    [
      [
        [%{wind: "Strong"}, [%{decision: "No"}]],
        [%{wind: "Weak"}, [%{decision: "Yes"}]]
      ]
    ]
  ],
  [
    %{outlook: "Sunny"},
    [
      [
        [%{humidity: "High"}, [%{decision: "No"}]],
        [%{humidity: "Normal"}, [%{decision: "Yes"}]]
      ]
    ]
  ]
]