:mod:`lookout.style.format.descriptions` ======================================== .. py:module:: lookout.style.format.descriptions .. autoapi-nested-parse:: Features and rules description utils. Module Contents --------------- .. function:: describe_rules(rules:List[Rule], feature_extractor:FeatureExtractor) Format the rules as a list of human-readable descriptions. :param rules: The list of rules to describe. :param feature_extractor: The FeatureExtractor used to create those rules. :return: A list of rule descriptions. .. function:: 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. :param rule: The rule to describe. :param feature_extractor: The FeatureExtractor used to create those rules. :return: The description of the rule. .. function:: hash_rule(rule:Rule, feature_extractor:FeatureExtractor) Hash rule contents to 8 hex characters. The same content produces the same hash all the time. :param rule: The rule to describe. :param feature_extractor: The FeatureExtractor used to create those rules. :return: String of length 8. .. function:: 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. :param rule: The rule to describe. :param feature_extractor: The FeatureExtractor used to create those rules. :return: The description of the rule. .. function:: describe_sample_bag(feature:BagFeature, values:ndarray) Describe a bag sample given its feature values. :param feature: The feature that computed the values to describe. :param values: The values to describe. :return: A string that describe the values of this feature. .. function:: describe_sample_categorical(feature:CategoricalFeature, values:ndarray) Describe a categorical sample given its feature values. :param feature: The feature that computed the values to describe. :param values: The values to describe. :return: A string that describe the values of this feature. .. function:: describe_sample_ordinal(feature:OrdinalFeature, values:ndarray) Describe an ordinal sample given its feature value. :param feature: The feature that computed the values to describe. :param values: The value to describe, in an array. :return: A string that describe the value of this feature. .. data:: SAMPLE_DESCRIBERS .. function:: describe_sample(feature:Feature, values:ndarray) Describe a sample given its feature value. :param feature: The feature that computed the values to describe. :param values: The value to describe, in an array. :return: A string that describe the value of this feature. .. function:: _describe_rule_splits_bag(feature:BagFeature, name:str, splits:List[RuleAttribute]) Describe parts of a bag rule in natural language. :param feature: The feature used for the splits to describe. :param name: The name to use for the feature used in the split. :param 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. :return: A string describing the given rule splits. .. function:: _describe_rule_splits_categorical(feature:CategoricalFeature, name:str, splits:List[RuleAttribute]) Describe parts of a categorical rule in natural language. :param feature: The feature used for the splits to describe. :param name: The name to use for the feature used in the split. :param 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. :return: A string describing the given rule splits. .. function:: _describe_rule_splits_ordinal(_, name:str, splits:List[RuleAttribute]) Describe a part of an ordinal rule in natural language. :param _: The feature used for the splits to describe. :param name: The name to use for the feature used in the split. :param 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. :return: A string describing the given rule splits. .. data:: RULE_SPLITS_DESCRIBERS .. function:: describe_rule_splits(feature:Feature, name:str, splits:List[RuleAttribute]) Describe a part of a rule in natural language. :param feature: The feature used for the splits to describe. :param name: The name to use for the feature used in the split. :param 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. :return: A string describing the given rule splits. .. function:: get_change_description(vnode:VirtualNode, feature_extractor:FeatureExtractor) Return the comment with regard to the correct node class. :param vnode: Changed node. "y" attribute is the predicted node label and "y_old" is the original one. :param feature_extractor: FeatureExtractor used to extract features. :return: String comment. .. function:: get_code_chunk(code_lines:Sequence[str], line_number:int) Return nice code snippet that can be inserted to github message. :param code_lines: Sequence of code lines without ending new line character. :param line_number: 1-based line number to print. :return: Code snippet. .. function:: dump_rule(model:FormatModel, rule_hash:str) Print the rule contained in the model by hash. :param model: Trained model. :param rule_hash: 8-char rule hash. :return: Nothing