eml.tree package

Submodules

eml.tree.describe module

class eml.tree.describe.DTNode(attr_name=None, attr_type=None, attr_range=None, _class=None)[source]

Bases: object

Class used to shape decision trees.

This class provides the possibility of building a decision tree and expanding it. In this project it will be used in order to port decision trees build via scikit-learn (REF TODO).

If the node has no attribute name, type, range and parent this means that the node is the root of a tree.

Parameters:
  • attr_name (string/int) – Name of the attribute, (default None)
  • attr_type (int) – Type of the attribute, either 0 (numeric) or 1 (symbolic), (default None)
  • attr_range ((float, float)) – Defines the inteval of the split. A split is defined by two ranges one for the left and one for the right, (default None)
  • _class (int) – Label of the class, if the current node is a leaf (default None)
_attr_name

Name of the attribute

Type:string/int
_attr_type

Type of the attribute, either 0 (numeric) or 1 (symbolic)

Type:int
_attr_range

Defines the inteval of the split. A split is defined by two ranges one for the left and one for the right

Type:(float, float)
_class

Label of the class, if the current node is a leaf

Type:int
_parent
Type:eml.tree.describe.DTNode
_children
Type:list(eml.tree.describe.DTNode)
thr_left

Defines the way the tree parses the intervals (TO BE REMOVED)

Type:bool
Raises:ValueError – If the given range is not valid
add_child(child)[source]

Add a child to the current node

Updates the list children and adds lower and upper bounds for the child if not already existing

Parameters:child (eml.tree.describe.DTNode) –
Returns:child
Return type:eml.tree.describe.DTNode
attr_name()[source]

Get the node’s attribute

Returns the name of the attribute to test in order to reach this node

Returns:Name – Name of the attribute
Return type:string/int
attr_range()[source]

Get the range of the node’s attribute

Returns the range that the sample’s attribute must respect in order to reach this node

Returns:Interval – Range of the attribute fo this node
Return type:(float, float)
attr_type()[source]

Get the type of the node’s attribute

Returns the type od the attribute to be tested in order to reach this node, it is either 0 (numeric) or 1 (symbolic)

eval(sample)[source]

Evalueates a sample

Returns the category associated to the sample in input according to the decision tree

Parameters:sample (list(att : value)) – List of attribute-value
Returns:Class – Classification of the sample
Return type:int
Raises:ValueError – If the sample is not well formed
get_children()[source]

Get the list of the children of the node

Returns:Children
Return type:list(eml.tree.describe.DTNode)
get_class()[source]

Get the class label of the current node

Returns:Class label – If this is a leaf an integer representing the class, None otherwise
Return type:int
lb(attr_name)[source]

Get lower bound of a attribute

Parameters:attr_ame (int) – Name of the attrbute of interest
Returns:Lower Bound – Lower bound of the attribute specified in input
Return type:float
set_class(_class)[source]

Set the class label

Parameters:_class (int) – Class label
Returns:
Return type:None
ub(attr_name)[source]

Get upper bound of a attribute

Parameters:attr_name (int) – Name of the attrbute of interest
Returns:Upper Bound – Upper bound of the attribute specified in input
Return type:float
update_lb(attr_name, value, tol=0.0001)[source]

Update lower bound of a attribute

Parameters:
  • attr_name (int) – Name of the attrbute of interest
  • value (float) – New lower bound value
  • tol (float) – Tollerance
Returns:

Acknowledge – True if the operation is succesfully exectued, False otherwise

Return type:

bool

update_ub(attr_name, value, tol=0.0001)[source]

Update upper bound of a attribute

Parameters:
  • attr_name (int) – Name of the attrbute of interest
  • value (float) – New upper bound value
  • tol (float) – Tollerance
Returns:

Acknowledge – True if the operation is succesfully exectued, False otherwise

Return type:

bool

eml.tree.embed module

eml.tree.embed.encode_backward_implications(bkd, tree, mdl, tree_in, tree_out, name)[source]

Encode the decision tree in the backend

Given a input and a output the tree is embeded into the optimization problem.

Parameters:
  • bkd (eml.backend.cplex_backend.CplexBackend) – Cplex backend
  • tree (eml.tree.describe.DTNode`) – Decision tree
  • mdl (docplex.mp.model.Model) – Cplex model
  • tree_in (list(docplex.mp.linear.Var)) – Input continuous variable
  • tree_out (docplex.mp.linear.Var) – Output continuous variable
  • name (string) – Name fo the tree
Returns:

Model Desciptor – Descriptor of the instance of EML

Return type:

eml.util.ModelDesc

Raises:

ValueError – If the threshold is in the ‘right’ branch or the tree has an output vector

eml.tree.process module

Module contents