lookout.style.format.descriptions

Features and rules description utils.

Module Contents

lookout.style.format.descriptions.describe_rules(rules:List[Rule], feature_extractor:FeatureExtractor)

Format the rules as a list of human-readable descriptions.

Parameters:
  • rules – The list of rules to describe.
  • feature_extractor – The FeatureExtractor used to create those rules.
Returns:

A list of rule descriptions.

lookout.style.format.descriptions.describe_rule(rule:Rule, feature_extractor:FeatureExtractor)

Format the rule as text.

We take features metadata to convert the integer indices to human-readable names.

Parameters:
  • rule – The rule to describe.
  • feature_extractor – The FeatureExtractor used to create those rules.
Returns:

The description of the rule.

lookout.style.format.descriptions.hash_rule(rule:Rule, feature_extractor:FeatureExtractor)

Hash rule contents to 8 hex characters. The same content produces the same hash all the time.

Parameters:
  • rule – The rule to describe.
  • feature_extractor – The FeatureExtractor used to create those rules.
Returns:

String of length 8.

lookout.style.format.descriptions.describe_rule_attrs(rule:Rule, feature_extractor:FeatureExtractor)

Format the rule as text.

We take features metadata to convert the integer indices to human-readable names.

Parameters:
  • rule – The rule to describe.
  • feature_extractor – The FeatureExtractor used to create those rules.
Returns:

The description of the rule.

lookout.style.format.descriptions.describe_sample_bag(feature:BagFeature, values:ndarray)

Describe a bag sample given its feature values.

Parameters:
  • feature – The feature that computed the values to describe.
  • values – The values to describe.
Returns:

A string that describe the values of this feature.

lookout.style.format.descriptions.describe_sample_categorical(feature:CategoricalFeature, values:ndarray)

Describe a categorical sample given its feature values.

Parameters:
  • feature – The feature that computed the values to describe.
  • values – The values to describe.
Returns:

A string that describe the values of this feature.

lookout.style.format.descriptions.describe_sample_ordinal(feature:OrdinalFeature, values:ndarray)

Describe an ordinal sample given its feature value.

Parameters:
  • feature – The feature that computed the values to describe.
  • values – The value to describe, in an array.
Returns:

A string that describe the value of this feature.

lookout.style.format.descriptions.SAMPLE_DESCRIBERS
lookout.style.format.descriptions.describe_sample(feature:Feature, values:ndarray)

Describe a sample given its feature value.

Parameters:
  • feature – The feature that computed the values to describe.
  • values – The value to describe, in an array.
Returns:

A string that describe the value of this feature.

lookout.style.format.descriptions._describe_rule_splits_bag(feature:BagFeature, name:str, splits:List[RuleAttribute])

Describe parts of a bag rule in natural language.

Parameters:
  • feature – The feature used for the splits to describe.
  • name – The name to use for the feature used in the split.
  • splits – List of tuples representing the splits to describe. The tuples contain the comparison, the threshold and the index of the feature used, useful in case of multi-values features.
Returns:

A string describing the given rule splits.

lookout.style.format.descriptions._describe_rule_splits_categorical(feature:CategoricalFeature, name:str, splits:List[RuleAttribute])

Describe parts of a categorical rule in natural language.

Parameters:
  • feature – The feature used for the splits to describe.
  • name – The name to use for the feature used in the split.
  • splits – List of tuples representing the splits to describe. The tuples contain the comparison, the threshold and the index of the feature used, useful in case of multi-values features.
Returns:

A string describing the given rule splits.

lookout.style.format.descriptions._describe_rule_splits_ordinal(_, name:str, splits:List[RuleAttribute])

Describe a part of an ordinal rule in natural language.

Parameters:
  • _ – The feature used for the splits to describe.
  • name – The name to use for the feature used in the split.
  • splits – List of the tuple representing the splits to describe. The tuples contain the comparison, the threshold and an ignored value here to be consistent with other types of features. The wrapping list is also needed for this reason.
Returns:

A string describing the given rule splits.

lookout.style.format.descriptions.RULE_SPLITS_DESCRIBERS
lookout.style.format.descriptions.describe_rule_splits(feature:Feature, name:str, splits:List[RuleAttribute])

Describe a part of a rule in natural language.

Parameters:
  • feature – The feature used for the splits to describe.
  • name – The name to use for the feature used in the split.
  • splits – List of the tuple representing the splits to describe. The tuples contain the comparison, the threshold and an ignored value here to be consistent with other types of features. The wrapping list is also needed for this reason.
Returns:

A string describing the given rule splits.

lookout.style.format.descriptions.get_change_description(vnode:VirtualNode, feature_extractor:FeatureExtractor)

Return the comment with regard to the correct node class.

Parameters:
  • vnode – Changed node. “y” attribute is the predicted node label and “y_old” is the original one.
  • feature_extractor – FeatureExtractor used to extract features.
Returns:

String comment.

lookout.style.format.descriptions.get_code_chunk(code_lines:Sequence[str], line_number:int)

Return nice code snippet that can be inserted to github message.

Parameters:
  • code_lines – Sequence of code lines without ending new line character.
  • line_number – 1-based line number to print.
Returns:

Code snippet.

lookout.style.format.descriptions.dump_rule(model:FormatModel, rule_hash:str)

Print the rule contained in the model by hash.

Parameters:
  • model – Trained model.
  • rule_hash – 8-char rule hash.
Returns:

Nothing