Decision Tree Model

The DecisionTree is the object used to represent the decision tree model. This module is responsible for all functionality of the package. A typical sequence of use is the following:

  • Create the nodes used to feed the tree (Module nodes).

  • Create the tree.

  • Build the internal structure of the tree.

  • Evaluate the tree.

  • Analyze plots and other results.

  • Modify the structure of the tree and repeat the analysis.

class smart_choice.decisiontree.DecisionTree(nodes)[source]

Bases: object

Decision tree representation.

Parameters

nodes (smart_choice.datanodes.DataNodes) – Types of nodes used in the tree. This parameter is created using the module Nodes.

Return type

None

copy()[source]

Creates a copy of the decision tree.

display(idx=0, max_deep=None, policy_suggestion=False, view='ev')[source]

Prints the tree as text diagram.

Parameters
  • idx (int) – Id number of the root of the tree to be exported. When it is zero, the entire tree is exported.

  • max_deep (Optional[int]) – Controls the maximum deep of the nodes in the tree exported as text.

  • policy_suggestion (bool) – When True exports only the subtree showing the nodes and branches relevants to the optimal decision (optimal strategy).

  • view (str) – Presented values in the tree: “ev” is the expected value; “eu” is the expected utility. “ce” is the certain equivalent.

Return type

None

evaluate()[source]

Calculates the values at the end of the tree (terminal nodes).

Return type

None

nodes()[source]

Prints the internal structure of the tree as a list of nodes.

Return type

None

plot(max_deep=None, policy_suggestion=False)[source]

Plots the tree.

Parameters
  • max_deep (Optional[int]) – maximum deep of the tree nodes to be plotted.

  • policy_suggestion (bool) – When True, it plots only the subtree showing the nodes and branches relevants to the optimal decision (optimal strategy).

rebuild()[source]

Build the tree using the structure information in the data nodes.

rollback(view='ev', utility_fn=None, risk_tolerance=0)[source]

Computes the preferred decision by calculating the expected values at each internal node, and returns the expected value of the preferred decision.

Computation begins at the terminal nodes towards the root node. In each chance node, the expected values are calculated as the sum of probabilities in each branch multiplied by the expected value in the corresponding node. For decision nodes, the expected value is the maximum (or minimum) value of its branches.

Parameters
  • view (str) –

    Value returned by the function:

    • ”ev”: expected value.

    • ”eu”: expected utility.

    • ”ce”: certainty equivalent.

  • utilitiy_fn

    Utility function used for the computations:

    • None: expected utility.

    • ”exp”: exponential utility function.

    • ”log”: logarithmic utility function.

  • risk_tolerance (float) – Risk tolerance of the decision-maker.

  • utility_fn (Optional[str]) –

Return type

float

smart_choice.decisiontree.jitter(x)[source]