xlemoo.tree_interpreter
- class XLEMOO.tree_interpreter.TreePath[source]
A custom type describing a typed dictionary to store tree paths.
- Parameters:
rules (List) – A list with each entry containing three elements: 1. feature index (int); 2. comparison operator (str), either ‘gte’ (greater or equal) or ‘lt’ (less than); 3. threshold value (float).
samples (int) – The number of samples that reached the endpoint of the path.
impurity (float) – Impurity of the last node of the path.
classification (int) – The final classification predicted by the path.
- XLEMOO.tree_interpreter.find_all_paths(tree: sklearn.tree) List[TreePath][source]
Find and return all decision paths of a decision tree. Currently supports only decision trees in the style present in the sklearn package.
- Parameters:
tree (sklearn.tree) – A trained decision tree.
- Returns:
A list of all the paths of the decision tree.
- Return type:
List[TreePath]
- XLEMOO.tree_interpreter.instantiate_tree_rules(paths: List[TreePath], n_features: int, feature_limits: List[Tuple[float, float]], n_samples: int, desired_classification: int) ndarray[source]
Given a list of TreePaths, instantiates a number of new samples that adhere to the rules and results in a specified classification if classified by a tree from which the TreePaths have been generated.
- Parameters:
paths (List[TreePath]) – see description in the docstring of ‘find_all_paths’
n_features (int) – number of input features.
feature_limits (List[Tuple[float, float]]) – the lower and upper limits of each input feature.
n_samples (int) – number of new samples to be instantiated for each path.
desired_classification (int) – the classification each considered path should end up to.
- Returns:
a 3D numpy array. The first dimension is the number of paths in paths that result in the desired classification. The second dimension if the number of desired samples. The third dimension are the instantiated feature values. If no rule has been specified in a path for some feature, that feature’s value is set to be a random value residing between its limits.
- Return type:
np.ndarray