lux.metrics.local_fidelity
- lux.metrics.local_fidelity(rule, dataset, features, categorical_indicator, prediction, class_label='class', average='micro')
Calculate coverage and various evaluation metrics for a given rule applied to a dataset.
- Parameters:
rule (dict) – A dictionary representing the rule to be evaluated. Each key corresponds to a feature, and the corresponding value is a list of conditions applied to that feature.
dataset (pandas.DataFrame) – The dataset on which the rule is applied. It should be a pandas DataFrame.
features (list) – A list of feature names in the dataset.
categorical_indicator (list) – A list indicating whether each feature is categorical or not. Each element of the list corresponds to a feature in features, with True indicating the feature is categorical and False indicating it is not.
prediction (int or float) – The prediction value assigned to instances covered by the rule.
class_label (str, optional) – The name of the column containing the class labels in the dataset. Default is ‘class’.
average (str, optional) – The averaging strategy for multiclass classification metrics. It can be one of {‘micro’, ‘macro’, ‘weighted’}. Default is ‘micro’.
- Returns:
A tuple containing: - coverage_ratio: The ratio of instances covered by the rule to the total instances in the dataset. - accuracy: The accuracy of the rule on the covered instances. - precision: The precision of the rule on the covered instances. - recall: The recall of the rule on the covered instances. - f1_score: The F1-score of the rule on the covered instances.
- Return type:
- Notes:
If rule contains conditions for features that are not present in the dataset, those conditions will be ignored.